diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4103ddb..ed813ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,15 +1,11 @@
-## 3.0.1 - May 5 2024
-
-- Support Flutter 3.22.1
-- Added Header Text
+## 3.1.0 - October 24 2024
+- Add some improvement
## 3.0.0 - March 10 2023
-
- Support Flutter 3.7.0
- Restructured package follow linter
## 2.0.2
-
- added localization for no_country text in italian and english (please open a pr with other languages if you know them 🙏)
- added possibility to inject a custom list of countries using `CountryCodePicker.countryList`
- minor fixes
diff --git a/CountryCodePicker.iml b/CountryCodePicker.iml
deleted file mode 100644
index e9e2e7e..0000000
--- a/CountryCodePicker.iml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/country_code_picker.iml b/country_code_picker.iml
deleted file mode 100644
index d20080d..0000000
--- a/country_code_picker.iml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/example/lib/main.dart b/example/lib/main.dart
index 5232cc0..a5191e7 100644
--- a/example/lib/main.dart
+++ b/example/lib/main.dart
@@ -2,12 +2,11 @@ import 'package:country_code_picker/country_code_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
-void main() => runApp( const MyApp());
+void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
-
@override
MyAppState createState() => MyAppState();
}
@@ -108,10 +107,12 @@ class MyAppState extends State {
favorite: const ['+39', 'FR'],
countryFilter: const ['IT', 'FR'],
showFlagDialog: false,
+ //You can set the margin between the flag and the country name to your taste.
+ margin: const EdgeInsets.symmetric(horizontal: 6),
comparator: (a, b) => b.name!.compareTo(a.name!),
//Get the country information relevant to the initial selection
onInit: (code) => debugPrint(
- "on init ${code!.name} ${code.dialCode} ${code.name}"),
+ "on init ${code?.name} ${code?.dialCode} ${code?.name}"),
),
CountryCodePicker(
onChanged: print,
diff --git a/example/pubspec.yaml b/example/pubspec.yaml
index 4c882ab..0d08d87 100644
--- a/example/pubspec.yaml
+++ b/example/pubspec.yaml
@@ -11,7 +11,7 @@ version: 1.0.0+1
publish_to: none
environment:
- sdk: '>=3.3.0 <4.0.0'
+ sdk: '>=2.17.0 <4.0.0'
dependencies:
flutter:
diff --git a/ios/Flutter/Generated.xcconfig b/ios/Flutter/Generated.xcconfig
deleted file mode 100644
index 79e59b7..0000000
--- a/ios/Flutter/Generated.xcconfig
+++ /dev/null
@@ -1,14 +0,0 @@
-// This is a generated file; do not edit or check into version control.
-FLUTTER_ROOT=C:\src\flutter
-FLUTTER_APPLICATION_PATH=C:\Users\RAHMAN\StudioProjects\CountryCodePicker
-COCOAPODS_PARALLEL_CODE_SIGN=true
-FLUTTER_TARGET=lib\main.dart
-FLUTTER_BUILD_DIR=build
-FLUTTER_BUILD_NAME=3.0.0
-FLUTTER_BUILD_NUMBER=3.0.0
-EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386
-EXCLUDED_ARCHS[sdk=iphoneos*]=armv7
-DART_OBFUSCATION=false
-TRACK_WIDGET_CREATION=true
-TREE_SHAKE_ICONS=false
-PACKAGE_CONFIG=.dart_tool/package_config.json
diff --git a/ios/Flutter/flutter_export_environment.sh b/ios/Flutter/flutter_export_environment.sh
deleted file mode 100755
index dda538a..0000000
--- a/ios/Flutter/flutter_export_environment.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-# This is a generated file; do not edit or check into version control.
-export "FLUTTER_ROOT=C:\src\flutter"
-export "FLUTTER_APPLICATION_PATH=C:\Users\RAHMAN\StudioProjects\CountryCodePicker"
-export "COCOAPODS_PARALLEL_CODE_SIGN=true"
-export "FLUTTER_TARGET=lib\main.dart"
-export "FLUTTER_BUILD_DIR=build"
-export "FLUTTER_BUILD_NAME=3.0.0"
-export "FLUTTER_BUILD_NUMBER=3.0.0"
-export "DART_OBFUSCATION=false"
-export "TRACK_WIDGET_CREATION=true"
-export "TREE_SHAKE_ICONS=false"
-export "PACKAGE_CONFIG=.dart_tool/package_config.json"
diff --git a/ios/Runner/GeneratedPluginRegistrant.h b/ios/Runner/GeneratedPluginRegistrant.h
deleted file mode 100644
index 7a89092..0000000
--- a/ios/Runner/GeneratedPluginRegistrant.h
+++ /dev/null
@@ -1,19 +0,0 @@
-//
-// Generated file. Do not edit.
-//
-
-// clang-format off
-
-#ifndef GeneratedPluginRegistrant_h
-#define GeneratedPluginRegistrant_h
-
-#import
-
-NS_ASSUME_NONNULL_BEGIN
-
-@interface GeneratedPluginRegistrant : NSObject
-+ (void)registerWithRegistry:(NSObject*)registry;
-@end
-
-NS_ASSUME_NONNULL_END
-#endif /* GeneratedPluginRegistrant_h */
diff --git a/ios/Runner/GeneratedPluginRegistrant.m b/ios/Runner/GeneratedPluginRegistrant.m
deleted file mode 100644
index efe65ec..0000000
--- a/ios/Runner/GeneratedPluginRegistrant.m
+++ /dev/null
@@ -1,14 +0,0 @@
-//
-// Generated file. Do not edit.
-//
-
-// clang-format off
-
-#import "GeneratedPluginRegistrant.h"
-
-@implementation GeneratedPluginRegistrant
-
-+ (void)registerWithRegistry:(NSObject*)registry {
-}
-
-@end
diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart
index d962ff0..1a3f871 100644
--- a/lib/country_code_picker.dart
+++ b/lib/country_code_picker.dart
@@ -19,6 +19,7 @@ class CountryCodePicker extends StatefulWidget {
final List favorite;
final TextStyle? textStyle;
final EdgeInsetsGeometry padding;
+ final EdgeInsetsGeometry? margin;
final bool showCountryOnly;
final InputDecoration searchDecoration;
final TextStyle? searchStyle;
@@ -99,6 +100,7 @@ class CountryCodePicker extends StatefulWidget {
this.favorite = const [],
this.textStyle,
this.padding = const EdgeInsets.all(8.0),
+ this.margin,
this.showCountryOnly = false,
this.searchDecoration = const InputDecoration(),
this.searchStyle,
@@ -127,7 +129,8 @@ class CountryCodePicker extends StatefulWidget {
this.dialogBackgroundColor,
this.closeIcon = const Icon(Icons.close),
this.countryList = codes,
- this.dialogItemPadding = const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
+ this.dialogItemPadding =
+ const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
this.searchPadding = const EdgeInsets.symmetric(horizontal: 24),
Key? key,
}) : super(key: key);
@@ -194,9 +197,10 @@ class CountryCodePickerState extends State {
? Clip.none
: Clip.hardEdge,
decoration: widget.flagDecoration,
- margin: widget.alignLeft
- ? const EdgeInsets.only(right: 16.0, left: 8.0)
- : const EdgeInsets.only(right: 16.0),
+ margin: widget.margin ??
+ (widget.alignLeft
+ ? const EdgeInsets.only(right: 16.0, left: 8.0)
+ : const EdgeInsets.only(right: 16.0)),
child: Image.asset(
selectedItem!.flagUri!,
package: 'country_code_picker',
@@ -221,9 +225,9 @@ class CountryCodePickerState extends State {
flex: widget.alignLeft ? 0 : 1,
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
child: Padding(
- padding: widget.alignLeft
+ padding: (widget.alignLeft
? const EdgeInsets.only(right: 16.0, left: 8.0)
- : const EdgeInsets.only(right: 16.0),
+ : const EdgeInsets.only(right: 16.0)),
child: Icon(
Icons.arrow_drop_down,
color: Colors.grey,
diff --git a/lib/src/country_code.dart b/lib/src/country_code.dart
index b8a3863..3a8069f 100644
--- a/lib/src/country_code.dart
+++ b/lib/src/country_code.dart
@@ -1,5 +1,6 @@
import 'package:collection/collection.dart' show IterableExtension;
import 'package:flutter/cupertino.dart';
+import 'package:flutter/foundation.dart' show kDebugMode;
import 'country_codes.dart';
import 'country_localizations.dart';
@@ -39,6 +40,15 @@ class CountryCode {
return CountryCode.fromJson(jsonCode!);
}
+ static CountryCode? tryFromCountryCode(String countryCode) {
+ try {
+ return CountryCode.fromCountryCode(countryCode);
+ } catch (e) {
+ if (kDebugMode) print('Failed to recognize country from countryCode: $countryCode');
+ return null;
+ }
+ }
+
factory CountryCode.fromDialCode(String dialCode) {
final Map? jsonCode = codes.firstWhereOrNull(
(code) => code['dial_code'] == dialCode,
@@ -46,6 +56,15 @@ class CountryCode {
return CountryCode.fromJson(jsonCode!);
}
+ static CountryCode? tryFromDialCode(String dialCode) {
+ try {
+ return CountryCode.fromDialCode(dialCode);
+ } catch (e) {
+ if (kDebugMode) print('Failed to recognize country from dialCode: $dialCode');
+ return null;
+ }
+ }
+
CountryCode localize(BuildContext context) {
return this
..name = CountryLocalizations.of(context)?.translate(code) ?? name;
diff --git a/lib/src/country_codes.dart b/lib/src/country_codes.dart
index 7e7c082..6d33a85 100644
--- a/lib/src/country_codes.dart
+++ b/lib/src/country_codes.dart
@@ -1,1237 +1,529 @@
const List