From 39d9d6de83d9bc5020658f7aafe831851028459c Mon Sep 17 00:00:00 2001 From: simon <59780143+simon-twonary@users.noreply.github.com> Date: Wed, 1 Apr 2020 23:11:20 -0400 Subject: [PATCH 01/20] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e12d084..9a1a005 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ Just add the `CountryLocalizations.delegate` in the list of your app delegates supportedLocales: [ Locale('en'), Locale('it'), - Locale('en'), + Locale('fr'), ], localizationsDelegates: [ CountryLocalizations.delegate, From 16f09e5ecf9f8d18d50da7b1941d3408915e6b10 Mon Sep 17 00:00:00 2001 From: Rafael Delos Santos Date: Thu, 2 Apr 2020 20:27:29 +1100 Subject: [PATCH 02/20] Allow to filter countries by locale in the dialog --- lib/country_code_picker.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 7e491da..f3fb1a1 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -51,6 +51,9 @@ class CountryCodePicker extends StatefulWidget { /// Use this property to change the order of the options final Comparator comparator; + // Enable filtering countries in the dialog using localizes string + final bool filterByLocale; + CountryCodePicker({ this.onChanged, this.onInit, @@ -74,6 +77,7 @@ class CountryCodePicker extends StatefulWidget { this.textOverflow = TextOverflow.ellipsis, this.comparator, this.customList, + this.filterByLocale = false, }); @override @@ -113,6 +117,9 @@ class _CountryCodePickerState extends State { @override Widget build(BuildContext context) { + if (widget.filterByLocale) { + this.elements = elements.map((e) => e.localize(context)).toList(); + } Widget _widget; if (widget.builder != null) _widget = InkWell( From 1e9495cf249a82468f0f45552f341ab8eb884076 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sat, 4 Apr 2020 14:13:04 +0200 Subject: [PATCH 03/20] fix search with localization and move elemen localization --- example/lib/main.dart | 4 ++-- lib/country_code.dart | 8 ++------ lib/country_code_picker.dart | 16 +++++----------- lib/selection_dialog.dart | 4 ++-- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index c65f5d5..0c0ee7f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -22,7 +22,7 @@ class _MyAppState extends State { supportedLocales: [ Locale('en'), Locale('it'), - Locale('en'), + Locale('fr'), ], localizationsDelegates: [ CountryLocalizations.delegate, @@ -72,7 +72,7 @@ class _MyAppState extends State { child: Padding( padding: const EdgeInsets.all(8.0), child: CountryCodePicker( - onChanged: print, + onChanged: (e) => print(e.toLongString()), initialSelection: 'TF', showCountryOnly: true, showOnlyCountryWhenClosed: true, diff --git a/lib/country_code.dart b/lib/country_code.dart index 13c1381..627b0c6 100644 --- a/lib/country_code.dart +++ b/lib/country_code.dart @@ -59,13 +59,9 @@ class CountryCode { @override String toString() => "$dialCode"; - String toLongString([BuildContext context]) => - "$dialCode ${toCountryStringOnly(context)}"; + String toLongString() => "$dialCode ${toCountryStringOnly()}"; - String toCountryStringOnly([BuildContext context]) { - if (context != null) { - return CountryLocalizations.of(context)?.translate(code) ?? name; - } + String toCountryStringOnly() { return '$name'; } } diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index f3fb1a1..063244b 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -51,9 +51,6 @@ class CountryCodePicker extends StatefulWidget { /// Use this property to change the order of the options final Comparator comparator; - // Enable filtering countries in the dialog using localizes string - final bool filterByLocale; - CountryCodePicker({ this.onChanged, this.onInit, @@ -77,7 +74,6 @@ class CountryCodePicker extends StatefulWidget { this.textOverflow = TextOverflow.ellipsis, this.comparator, this.customList, - this.filterByLocale = false, }); @override @@ -117,14 +113,11 @@ class _CountryCodePickerState extends State { @override Widget build(BuildContext context) { - if (widget.filterByLocale) { - this.elements = elements.map((e) => e.localize(context)).toList(); - } Widget _widget; if (widget.builder != null) _widget = InkWell( onTap: _showSelectionDialog, - child: widget.builder(selectedItem.localize(context)), + child: widget.builder(selectedItem), ); else { _widget = FlatButton( @@ -153,7 +146,7 @@ class _CountryCodePickerState extends State { fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, child: Text( widget.showOnlyCountryWhenClosed - ? selectedItem.toCountryStringOnly(context) + ? selectedItem.toCountryStringOnly() : selectedItem.toString(), style: widget.textStyle ?? Theme.of(context).textTheme.button, overflow: widget.textOverflow, @@ -170,6 +163,7 @@ class _CountryCodePickerState extends State { void didUpdateWidget(CountryCodePicker oldWidget) { super.didUpdateWidget(oldWidget); + this.elements = elements.map((e) => e.localize(context)).toList(); _onInit(selectedItem); if (oldWidget.initialSelection != widget.initialSelection) { @@ -234,13 +228,13 @@ class _CountryCodePickerState extends State { void _publishSelection(CountryCode e) { if (widget.onChanged != null) { - widget.onChanged(e.localize(context)); + widget.onChanged(e); } } void _onInit(CountryCode e) { if (widget.onInit != null) { - widget.onInit(e.localize(context)); + widget.onInit(e); } } } diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index eb010c4..ac46393 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -123,8 +123,8 @@ class _SelectionDialogState extends State { flex: 4, child: Text( widget.showCountryOnly - ? e.toCountryStringOnly(context) - : e.toLongString(context), + ? e.toCountryStringOnly() + : e.toLongString(), overflow: TextOverflow.fade, ), ), From bb7d3c75c860ef70e6ed4432c11e0b601fe67464 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sat, 4 Apr 2020 16:15:25 +0200 Subject: [PATCH 04/20] refs #59: add dialog size --- lib/country_code_picker.dart | 5 +++++ lib/selection_dialog.dart | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 7e491da..6088deb 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -22,6 +22,9 @@ class CountryCodePicker extends StatefulWidget { final bool enabled; final TextOverflow textOverflow; + /// the size of the selection dialog + final Size dialogSize; + /// used to customize the country list final List customList; @@ -74,6 +77,7 @@ class CountryCodePicker extends StatefulWidget { this.textOverflow = TextOverflow.ellipsis, this.comparator, this.customList, + this.dialogSize, }); @override @@ -213,6 +217,7 @@ class _CountryCodePickerState extends State { searchStyle: widget.searchStyle, showFlag: widget.showFlag || (widget.showFlagDialog == true), flagWidth: widget.flagWidth, + size: widget.dialogSize, ), ).then((e) { if (e != null) { diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index eb010c4..ae6beb2 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -10,6 +10,7 @@ class SelectionDialog extends StatefulWidget { final WidgetBuilder emptySearchBuilder; final bool showFlag; final double flagWidth; + final Size size; /// elements passed as favorite final List favoriteElements; @@ -24,6 +25,7 @@ class SelectionDialog extends StatefulWidget { this.searchStyle, this.showFlag, this.flagWidth = 32, + this.size, }) : assert(searchDecoration != null, 'searchDecoration must not be null!'), this.searchDecoration = searchDecoration.copyWith(prefixIcon: Icon(Icons.search)), @@ -64,8 +66,9 @@ class _SelectionDialogState extends State { ), children: [ Container( - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height * 0.7, + width: widget.size?.width ?? MediaQuery.of(context).size.width, + height: + widget.size?.height ?? MediaQuery.of(context).size.height * 0.7, child: ListView( children: [ widget.favoriteElements.isEmpty From c74dcf43ca8334d4f17139732498b27bef225009 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sat, 4 Apr 2020 16:25:19 +0200 Subject: [PATCH 05/20] refs #60: expose state to let use a key to open the dialog --- example/lib/main.dart | 6 +----- lib/country_code_picker.dart | 15 ++++++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index c65f5d5..6b31564 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -11,11 +11,6 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { - @override - void initState() { - super.initState(); - } - @override Widget build(BuildContext context) { return new MaterialApp( @@ -38,6 +33,7 @@ class _MyAppState extends State { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ CountryCodePicker( + key: key, onChanged: print, // Initial selection and favorite can be one of code ('IT') OR dial_code('+39') initialSelection: 'IT', diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 6088deb..7dbaac5 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -78,7 +78,8 @@ class CountryCodePicker extends StatefulWidget { this.comparator, this.customList, this.dialogSize, - }); + Key key, + }) : super(key: key); @override State createState() { @@ -104,29 +105,29 @@ class CountryCodePicker extends StatefulWidget { elements = elements.where((c) => countryFilter.contains(c.code)).toList(); } - return _CountryCodePickerState(elements); + return CountryCodePickerState(elements); } } -class _CountryCodePickerState extends State { +class CountryCodePickerState extends State { CountryCode selectedItem; List elements = []; List favoriteElements = []; - _CountryCodePickerState(this.elements); + CountryCodePickerState(this.elements); @override Widget build(BuildContext context) { Widget _widget; if (widget.builder != null) _widget = InkWell( - onTap: _showSelectionDialog, + onTap: showCountryCodePickerDialog, child: widget.builder(selectedItem.localize(context)), ); else { _widget = FlatButton( padding: widget.padding, - onPressed: widget.enabled ? _showSelectionDialog : null, + onPressed: widget.enabled ? showCountryCodePickerDialog : null, child: Flex( direction: Axis.horizontal, mainAxisSize: MainAxisSize.min, @@ -205,7 +206,7 @@ class _CountryCodePickerState extends State { super.initState(); } - void _showSelectionDialog() { + void showCountryCodePickerDialog() { showDialog( context: context, builder: (_) => SelectionDialog( From f4a23020bf8bdef80d945737c62dfbc18eefd244 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sat, 4 Apr 2020 16:25:36 +0200 Subject: [PATCH 06/20] fix example --- example/lib/main.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 6b31564..cdebcaf 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -33,7 +33,6 @@ class _MyAppState extends State { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ CountryCodePicker( - key: key, onChanged: print, // Initial selection and favorite can be one of code ('IT') OR dial_code('+39') initialSelection: 'IT', From 47a3336058a918eb8bc5530f6302444b5149c4c8 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sat, 4 Apr 2020 16:41:37 +0200 Subject: [PATCH 07/20] version bump --- CHANGELOG.md | 8 ++++++++ example/lib/main.dart | 2 +- lib/country_code_picker.dart | 24 +++++++++--------------- pubspec.yaml | 2 +- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 319110d..1df6984 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 1.3.8 + +- Expose state to let use a key to open the dialog + +- Add dialog size config + +- Remove customList and fix countryFilter + ## 1.3.7 - Add `customList` property diff --git a/example/lib/main.dart b/example/lib/main.dart index ad5a759..fe90dc3 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -38,7 +38,7 @@ class _MyAppState extends State { initialSelection: 'IT', favorite: ['+39', 'FR'], showFlag: false, - customList: ['IT', 'FR'], + countryFilter: ['IT', 'FR'], showFlagDialog: true, comparator: (a, b) => b.name.compareTo(a.name), //Get the country information relevant to the initial selection diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index e522a69..42cd306 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -26,7 +26,7 @@ class CountryCodePicker extends StatefulWidget { final Size dialogSize; /// used to customize the country list - final List customList; + final List countryFilter; /// shows the name of the country instead of the dialcode final bool showOnlyCountryWhenClosed; @@ -45,9 +45,6 @@ class CountryCodePicker extends StatefulWidget { final bool showFlagDialog; - /// contains the country codes to load only the specified countries. - final List countryFilter; - /// Width of the flag images final double flagWidth; @@ -59,7 +56,6 @@ class CountryCodePicker extends StatefulWidget { this.onInit, this.initialSelection, this.favorite = const [], - this.countryFilter = const [], this.textStyle, this.padding = const EdgeInsets.all(0.0), this.showCountryOnly = false, @@ -76,7 +72,7 @@ class CountryCodePicker extends StatefulWidget { this.enabled = true, this.textOverflow = TextOverflow.ellipsis, this.comparator, - this.customList, + this.countryFilter, this.dialogSize, Key key, }) : super(key: key); @@ -92,19 +88,17 @@ class CountryCodePicker extends StatefulWidget { elements.sort(comparator); } - if (customList != null) { + if (countryFilter != null && countryFilter.isNotEmpty) { + final uppercaseCustomList = + countryFilter.map((c) => c.toUpperCase()).toList(); elements = elements .where((c) => - customList.contains(c.code) || - customList.contains(c.name) || - customList.contains(c.dialCode)) + uppercaseCustomList.contains(c.code) || + uppercaseCustomList.contains(c.name) || + uppercaseCustomList.contains(c.dialCode)) .toList(); } - if (countryFilter.length > 0) { - elements = elements.where((c) => countryFilter.contains(c.code)).toList(); - } - return CountryCodePickerState(elements); } } @@ -186,7 +180,7 @@ class CountryCodePickerState extends State { } @override - initState() { + void initState() { if (widget.initialSelection != null) { selectedItem = elements.firstWhere( (e) => diff --git a/pubspec.yaml b/pubspec.yaml index d44cccf..68990d3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: country_code_picker description: A flutter package for showing a country code selector. In addition it gives the possibility to select a list of favorites countries, as well as to search using a simple searchbox -version: 1.3.7 +version: 1.3.8 homepage: https://github.com/imtoori/CountryCodePicker environment: From e9be040731a1caf5f03ce33037ce230502fbd4d7 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sat, 4 Apr 2020 16:45:38 +0200 Subject: [PATCH 08/20] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1df6984..c12b8ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - Remove customList and fix countryFilter +- Fix filtering with localization + ## 1.3.7 - Add `customList` property From 77ee2e9b1df07046ba650b761c3d12cbd0aba1ff Mon Sep 17 00:00:00 2001 From: simon <59780143+simon-twonary@users.noreply.github.com> Date: Sat, 4 Apr 2020 18:46:08 -0400 Subject: [PATCH 09/20] Update pubspec.yaml --- pubspec.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/pubspec.yaml b/pubspec.yaml index d44cccf..8c7a621 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,3 +16,4 @@ flutter: - packages/country_code_picker/i18n/en.json - packages/country_code_picker/i18n/it.json - packages/country_code_picker/i18n/fr.json + - packages/country_code_picker/i18n/es.json From 09bcd6e6cb56dcef780b10e2083e8c8ac9a7ca0a Mon Sep 17 00:00:00 2001 From: simon <59780143+simon-twonary@users.noreply.github.com> Date: Sat, 4 Apr 2020 18:47:20 -0400 Subject: [PATCH 10/20] Update country_localizations.dart --- lib/country_localizations.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/country_localizations.dart b/lib/country_localizations.dart index 873735d..2705fd8 100644 --- a/lib/country_localizations.dart +++ b/lib/country_localizations.dart @@ -48,6 +48,7 @@ class _CountryLocalizationsDelegate 'en', 'it', 'fr', + 'es', ].contains(locale.languageCode); } From 12edc3ff90302de9d0fd6026bf90be1d7326d682 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sun, 5 Apr 2020 11:56:06 +0200 Subject: [PATCH 11/20] refs #63: add hideSearch property --- example/lib/main.dart | 1 + lib/country_code_picker.dart | 7 ++++++- lib/selection_dialog.dart | 17 ++++++++++------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index fe90dc3..5bf6834 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -52,6 +52,7 @@ class _MyAppState extends State { child: CountryCodePicker( onChanged: print, initialSelection: 'TF', + hideSearch: true, showCountryOnly: true, showOnlyCountryWhenClosed: true, alignLeft: true, diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 42cd306..9a2eb54 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -51,6 +51,9 @@ class CountryCodePicker extends StatefulWidget { /// Use this property to change the order of the options final Comparator comparator; + /// Set to true if you want to hide the search part + final bool hideSearch; + CountryCodePicker({ this.onChanged, this.onInit, @@ -73,6 +76,7 @@ class CountryCodePicker extends StatefulWidget { this.textOverflow = TextOverflow.ellipsis, this.comparator, this.countryFilter, + this.hideSearch = false, this.dialogSize, Key key, }) : super(key: key); @@ -181,6 +185,7 @@ class CountryCodePickerState extends State { @override void initState() { + super.initState(); if (widget.initialSelection != null) { selectedItem = elements.firstWhere( (e) => @@ -198,7 +203,6 @@ class CountryCodePickerState extends State { orElse: () => null) != null) .toList(); - super.initState(); } void showCountryCodePickerDialog() { @@ -214,6 +218,7 @@ class CountryCodePickerState extends State { showFlag: widget.showFlag || (widget.showFlagDialog == true), flagWidth: widget.flagWidth, size: widget.dialogSize, + hideSearch: widget.hideSearch, ), ).then((e) { if (e != null) { diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index 15d0a65..60e429e 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -11,6 +11,7 @@ class SelectionDialog extends StatefulWidget { final bool showFlag; final double flagWidth; final Size size; + final bool hideSearch; /// elements passed as favorite final List favoriteElements; @@ -26,6 +27,7 @@ class SelectionDialog extends StatefulWidget { this.showFlag, this.flagWidth = 32, this.size, + this.hideSearch = false, }) : assert(searchDecoration != null, 'searchDecoration must not be null!'), this.searchDecoration = searchDecoration.copyWith(prefixIcon: Icon(Icons.search)), @@ -54,14 +56,15 @@ class _SelectionDialogState extends State { ), onPressed: () => Navigator.pop(context), ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 24), - child: TextField( - style: widget.searchStyle, - decoration: widget.searchDecoration, - onChanged: _filterElements, + if (!widget.hideSearch) + Padding( + padding: const EdgeInsets.symmetric(horizontal: 24), + child: TextField( + style: widget.searchStyle, + decoration: widget.searchDecoration, + onChanged: _filterElements, + ), ), - ), ], ), children: [ From 0b442aafdff56211a210fee8f9fb7f32646c9a06 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sun, 5 Apr 2020 11:57:11 +0200 Subject: [PATCH 12/20] version bump --- CHANGELOG.md | 6 ++++++ README.md | 1 + pubspec.yaml | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c12b8ce..e035a45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.3.9 + +- Add hideSearch property + +- Add spanish support + ## 1.3.8 - Expose state to let use a key to open the dialog diff --git a/README.md b/README.md index 9a1a005..c26218b 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Just add the `CountryLocalizations.delegate` in the list of your app delegates Locale('en'), Locale('it'), Locale('fr'), + Locale('es'), ], localizationsDelegates: [ CountryLocalizations.delegate, diff --git a/pubspec.yaml b/pubspec.yaml index 7a928e1..f9dcbaa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: country_code_picker description: A flutter package for showing a country code selector. In addition it gives the possibility to select a list of favorites countries, as well as to search using a simple searchbox -version: 1.3.8 +version: 1.3.9 homepage: https://github.com/imtoori/CountryCodePicker environment: From 8f9959cbe6c01cf0d5cf6243dfb13fe4ee55c4ec Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sun, 5 Apr 2020 12:29:52 +0200 Subject: [PATCH 13/20] update readme --- README.md | 30 ++++++++++++++++++++++++++++++ example/lib/main.dart | 1 + lib/country_code_picker.dart | 15 ++++++++++----- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c26218b..e9fbc25 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,36 @@ Just add the `CountryLocalizations.delegate` in the list of your app delegates ], ``` +## Customization + +Here is a list of properties available to customize your widget: + +| Name | Type | Description | +|-|-| +|onChanged| ValueChanged | callback invoked when the selection changes | +|onInit| ValueChanged | callback invoked during initialization of the widget | +|initialSelection| String | used to set the initial selected value | +|favorite| List | used to populate the favorite country list | +|textStyle| TextStyle | TextStyle applied to the widget button | +|padding| EdgeInsetsGeometry | the padding applied to the button | +|showCountryOnly| bool | true if you want to see only the countries in the selection dialog | +|searchDecoration| InputDecoration | decoration applied to the TextField search widget | +|searchStyle| TextStyle | style applied to the TextField search widget text | +|emptySearchBuilder| WidgetBuilder | use this to customize the widget used when the search returns 0 elements | +|builder| Function(CountryCode) | use this to build a custom widget instead of the default FlatButton | +|enabled| bool | set to false to disable the widget | +|textOverflow| TextOverflow | the button text overflow behaviour | +|dialogSize| Size | the size of the selection dialog | +|countryFilter| List | uses a list of strings to filter a sublist of countries | +|showOnlyCountryWhenClosed| bool | if true it'll show only the country | +|alignLeft| bool | aligns the flag and the Text to the left | +|showFlag| bool | shows the flag everywhere | +|showFlagMain| bool | shows the flag only when closed | +|showFlagDialog| bool | shows the flag only in dialog | +|flagWidth| double | the width of the flags | +|comparator| Comparator | use this to sort the countries in the selection dialog | +|hideSearch| bool | if true the search feature will be disabled | + ## Contributions Contributions of any kind are more than welcome! Feel free to fork and improve country_code_picker in any way you want, make a pull request, or open an issue. diff --git a/example/lib/main.dart b/example/lib/main.dart index 5bf6834..dc33bff 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -18,6 +18,7 @@ class _MyAppState extends State { Locale('en'), Locale('it'), Locale('fr'), + Locale('es'), ], localizationsDelegates: [ CountryLocalizations.delegate, diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 9a2eb54..9602e5c 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -118,9 +118,9 @@ class CountryCodePickerState extends State { Widget build(BuildContext context) { Widget _widget; if (widget.builder != null) - _widget = InkWell( + _widget = GestureDetector( onTap: showCountryCodePickerDialog, - child: widget.builder(selectedItem.localize(context)), + child: widget.builder(selectedItem), ); else { _widget = FlatButton( @@ -175,7 +175,8 @@ class CountryCodePickerState extends State { (e) => (e.code.toUpperCase() == widget.initialSelection.toUpperCase()) || - (e.dialCode == widget.initialSelection.toString()), + (e.dialCode == widget.initialSelection) || + (e.name.toUpperCase() == widget.initialSelection.toUpperCase()), orElse: () => elements[0]); } else { selectedItem = elements[0]; @@ -190,7 +191,8 @@ class CountryCodePickerState extends State { selectedItem = elements.firstWhere( (e) => (e.code.toUpperCase() == widget.initialSelection.toUpperCase()) || - (e.dialCode == widget.initialSelection.toString()), + (e.dialCode == widget.initialSelection) || + (e.name.toUpperCase() == widget.initialSelection.toUpperCase()), orElse: () => elements[0]); } else { selectedItem = elements[0]; @@ -199,7 +201,10 @@ class CountryCodePickerState extends State { favoriteElements = elements .where((e) => widget.favorite.firstWhere( - (f) => e.code == f.toUpperCase() || e.dialCode == f.toString(), + (f) => + e.code.toUpperCase() == f.toUpperCase() || + e.dialCode == f || + e.name.toUpperCase() == f.toUpperCase(), orElse: () => null) != null) .toList(); From 7ade439518a4647b3a015e22a3ce052ff51e11c9 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sun, 5 Apr 2020 12:31:17 +0200 Subject: [PATCH 14/20] Update README.md --- README.md | 2 +- lib/country_code_picker.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e9fbc25..95d1dad 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Just add the `CountryLocalizations.delegate` in the list of your app delegates Here is a list of properties available to customize your widget: | Name | Type | Description | -|-|-| +|-----|-----|------| |onChanged| ValueChanged | callback invoked when the selection changes | |onInit| ValueChanged | callback invoked during initialization of the widget | |initialSelection| String | used to set the initial selected value | diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 9602e5c..5b5ac9b 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -118,7 +118,7 @@ class CountryCodePickerState extends State { Widget build(BuildContext context) { Widget _widget; if (widget.builder != null) - _widget = GestureDetector( + _widget = InkWell( onTap: showCountryCodePickerDialog, child: widget.builder(selectedItem), ); From 81c668ed439d8d8f5a9c4223ac4059163a2d4354 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Tue, 7 Apr 2020 14:41:30 +0200 Subject: [PATCH 15/20] use didchangedependencies --- example/lib/main.dart | 3 ++- lib/country_code_picker.dart | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index dc33bff..a92be9c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -43,7 +43,8 @@ class _MyAppState extends State { showFlagDialog: true, comparator: (a, b) => b.name.compareTo(a.name), //Get the country information relevant to the initial selection - onInit: (code) => print("${code.name} ${code.dialCode}"), + onInit: (code) => + print("on init ${code.name} ${code.dialCode}"), ), SizedBox( width: 400, diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 5b5ac9b..c2cdea9 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -163,11 +163,15 @@ class CountryCodePickerState extends State { } @override - void didUpdateWidget(CountryCodePicker oldWidget) { - super.didUpdateWidget(oldWidget); + void didChangeDependencies() { + super.didChangeDependencies(); this.elements = elements.map((e) => e.localize(context)).toList(); - _onInit(selectedItem); + } + + @override + void didUpdateWidget(CountryCodePicker oldWidget) { + super.didUpdateWidget(oldWidget); if (oldWidget.initialSelection != widget.initialSelection) { if (widget.initialSelection != null) { From 354f4395b703a6bf6c50d4cc2c4e50eb5f32c83d Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Tue, 7 Apr 2020 15:03:38 +0200 Subject: [PATCH 16/20] bump version --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e035a45..5363a97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.3.10 + +- Fix initialization + ## 1.3.9 - Add hideSearch property diff --git a/pubspec.yaml b/pubspec.yaml index f9dcbaa..e280389 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: country_code_picker description: A flutter package for showing a country code selector. In addition it gives the possibility to select a list of favorites countries, as well as to search using a simple searchbox -version: 1.3.9 +version: 1.3.10 homepage: https://github.com/imtoori/CountryCodePicker environment: From a94a13bd4732662bc3661cb80e7cd81edadf98f5 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Tue, 7 Apr 2020 15:12:04 +0200 Subject: [PATCH 17/20] bump version --- CHANGELOG.md | 2 +- lib/country_code_picker.dart | 4 ++++ pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5363a97..04e94f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.3.10 +## 1.3.11 - Fix initialization diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index c2cdea9..f6edfdb 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -185,12 +185,14 @@ class CountryCodePickerState extends State { } else { selectedItem = elements[0]; } + _onInit(selectedItem); } } @override void initState() { super.initState(); + if (widget.initialSelection != null) { selectedItem = elements.firstWhere( (e) => @@ -202,6 +204,8 @@ class CountryCodePickerState extends State { selectedItem = elements[0]; } + _onInit(selectedItem); + favoriteElements = elements .where((e) => widget.favorite.firstWhere( diff --git a/pubspec.yaml b/pubspec.yaml index e280389..a054a14 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: country_code_picker description: A flutter package for showing a country code selector. In addition it gives the possibility to select a list of favorites countries, as well as to search using a simple searchbox -version: 1.3.10 +version: 1.3.11 homepage: https://github.com/imtoori/CountryCodePicker environment: From 51fa3d7b9a54b5713941bbf6557dda286cbbf79e Mon Sep 17 00:00:00 2001 From: "km.yiu" Date: Wed, 29 Apr 2020 16:02:46 +0800 Subject: [PATCH 18/20] allow to edit dialog textStyle --- lib/country_code_picker.dart | 3 +++ lib/selection_dialog.dart | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index f6edfdb..3a56eed 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -17,6 +17,7 @@ class CountryCodePicker extends StatefulWidget { final bool showCountryOnly; final InputDecoration searchDecoration; final TextStyle searchStyle; + final TextStyle dialogTextStyle; final WidgetBuilder emptySearchBuilder; final Function(CountryCode) builder; final bool enabled; @@ -64,6 +65,7 @@ class CountryCodePicker extends StatefulWidget { this.showCountryOnly = false, this.searchDecoration = const InputDecoration(), this.searchStyle, + this.dialogTextStyle, this.emptySearchBuilder, this.showOnlyCountryWhenClosed = false, this.alignLeft = false, @@ -228,6 +230,7 @@ class CountryCodePickerState extends State { emptySearchBuilder: widget.emptySearchBuilder, searchDecoration: widget.searchDecoration, searchStyle: widget.searchStyle, + textStyle: widget.dialogTextStyle, showFlag: widget.showFlag || (widget.showFlagDialog == true), flagWidth: widget.flagWidth, size: widget.dialogSize, diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index 60e429e..3c66f7d 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -7,6 +7,7 @@ class SelectionDialog extends StatefulWidget { final bool showCountryOnly; final InputDecoration searchDecoration; final TextStyle searchStyle; + final TextStyle textStyle; final WidgetBuilder emptySearchBuilder; final bool showFlag; final double flagWidth; @@ -24,6 +25,7 @@ class SelectionDialog extends StatefulWidget { this.emptySearchBuilder, InputDecoration searchDecoration = const InputDecoration(), this.searchStyle, + this.textStyle, this.showFlag, this.flagWidth = 32, this.size, @@ -132,6 +134,7 @@ class _SelectionDialogState extends State { ? e.toCountryStringOnly() : e.toLongString(), overflow: TextOverflow.fade, + style: widget.textStyle, ), ), ], From 0caf8e4f2c9d23c6228c87b7ab7438503c8715f8 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Wed, 29 Apr 2020 19:23:12 +0200 Subject: [PATCH 19/20] version bump --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04e94f9..b19944f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.3.12 + +- Allow to edit dialog textStyle + ## 1.3.11 - Fix initialization diff --git a/pubspec.yaml b/pubspec.yaml index a054a14..6c59c74 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: country_code_picker description: A flutter package for showing a country code selector. In addition it gives the possibility to select a list of favorites countries, as well as to search using a simple searchbox -version: 1.3.11 +version: 1.3.12 homepage: https://github.com/imtoori/CountryCodePicker environment: From ed136d0a0342c0332873d9a3d3c738a8bf0541c7 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sun, 3 May 2020 15:40:59 +0200 Subject: [PATCH 20/20] fix cayman islands code --- CHANGELOG.md | 4 ++++ lib/country_codes.dart | 2 +- pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b19944f..8535eb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.3.12+1 + +- Fix Cayman Islands code + ## 1.3.12 - Allow to edit dialog textStyle diff --git a/lib/country_codes.dart b/lib/country_codes.dart index 441f66e..826d931 100644 --- a/lib/country_codes.dart +++ b/lib/country_codes.dart @@ -202,7 +202,7 @@ List> codes = [ { "name": "Cayman Islands", "code": "KY", - "dial_code": "+ 345", + "dial_code": "+1345", }, { "name": "Ködörösêse tî Bêafrîka", diff --git a/pubspec.yaml b/pubspec.yaml index 6c59c74..3fae238 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: country_code_picker description: A flutter package for showing a country code selector. In addition it gives the possibility to select a list of favorites countries, as well as to search using a simple searchbox -version: 1.3.12 +version: 1.3.12+1 homepage: https://github.com/imtoori/CountryCodePicker environment: