From 3bbd4e7e62ff64f11290e12378930fe271166b3a Mon Sep 17 00:00:00 2001 From: Nilashish Roy Date: Fri, 7 Feb 2025 21:29:56 +0600 Subject: [PATCH 1/4] Fixed the Issue #50. Typo: "Country" not "County" #50 Fixed the header text getting Spelling error. --- lib/country_code_picker.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 52436aa..3d6f320 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -156,7 +156,7 @@ class CountryCodePicker extends StatefulWidget { const EdgeInsets.symmetric(horizontal: 24, vertical: 8), this.searchPadding = const EdgeInsets.symmetric(horizontal: 24), this.headerAlignment = MainAxisAlignment.spaceBetween, - this.headerText = "Select County", + this.headerText = "Select Country", this.headerTextStyle = const TextStyle(fontSize: 18, fontWeight: FontWeight.bold), this.hideHeaderText = false, From 282ed6e0beb0e9a562e84cf0108fc557855a4650 Mon Sep 17 00:00:00 2001 From: Nilashish Roy Date: Fri, 7 Feb 2025 21:42:27 +0600 Subject: [PATCH 2/4] Fixed the Issue #45. issue with syria flag #45 Updated the syrian flag --- flags/sy.png | Bin 494 -> 2411 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/flags/sy.png b/flags/sy.png index 2ba6f6aa0e6cecef9ab608155674c50a0a8b196f..c1bb556b876838dbb3d70b1e9a890cc26588fca2 100644 GIT binary patch literal 2411 zcmV-x36%DUP)6 zJN_U_jN_05W5C2JAt-5(XcMInQ9@9F4RlcpCFDC?aOYPND~8D;k5l7k4&^2v-DU8>(t%r4&_7sWP*!>q3ld!_0~mRSk6| zBJN(yBq%$H1!GGN?#zfFf`B{jY{$KrF(Yo`trrBM7L4r#p_F1qj0jjk1vhpQk;si^-Aj>Df{5tER3lq4GgaKxJ&6e5?%D!@oycRq`!QP)5x_SAA`&)rUB_13 zJ;vznec!8UUDxj3wymnN6%olft7=Ng-9-dw+cs!oCo=Jl?Kv(8n+z+IMB@LUP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ZSYnMEGMpZM7Ezy4AeR+j$p`~Uu*Pe1g9hwBigST(5V9hJ%)D_}o(=BXo}|Ku&7{qx)A z?DXT`eBqg2-~QkO%+&}bN$8=sMgqZ@tpCSz&))ne_ulp8zeKWsbUCh2`<p8a@!S9M&8#L)ldUqQk(F9|iNhRZr5g+eIjIM_@i=e#}~?UFF; zO24{7FdOJvnWPke5W=LCFq+FfVQO(T?``Hz?OknF^I*)-Q_xzSURfQ;a#i}0N1e_0 zq4cJML6^(0swIyls0qc)5Cdg{8Z*iUX&{3`0D%rXfkLUO>=ki>m7sWTB!<$hOB0aj zZNzJ&r7xg?0=;8wGTjx1ls=)Cn+XLnjVQ!y*-=wG3fAK)1yGHt6hlI=v4I1^TZyB* zDO4zk;~BC*009T{%3}n>iWF2R{SX6Ha=|r(f)z}_9Cy@-PUBJ`;ttYNG+S|qqGReqLR50dE_CXC($C~JFVi*)qp)ndf;bV7%4G!*X5>?!V>#n=* dy6fH+{s6v$dbBoc@*V&H002ovPDHLkV1m5bb>RR2 delta 481 zcmV<70UrMA67B<#7k?)R0{{R3WHZ|s0002YP)t-s00000000320V^vj%gf9E|Nrp! z^!)z));LPX;nbtgxo)$N-tOkb;nU6J+1l*m*z4hcyPQ|0eEIzP2Yo?HpL1=oj`;if z`u+Rp^X<*$*v{qITBv|1jadMAIos^yQ>1$9^zd@El8eHn0DpHl!{5>L`SuxyPvGz8 z8-z@Z!KU5q<^KQv;_&JB`}wTXz7c*y#NpB(h*F%(v+wuwtJ1wRlVa`m@fL$hQ=@u9 znQOS($rXc2xY@~4qe*R8_f%!k?X(MV6erWsVYS|5=goR`8BLQoDq8+|dkdC(3lmxUWngb{F?Q_n zE?lc)69SU|skMU Date: Fri, 7 Feb 2025 23:00:18 +0600 Subject: [PATCH 3/4] Fixed the Issue #48. Localization is hardcoded to english since 3.2.0 #48 Added the localization use and boolean --- example/lib/main.dart | 1 + lib/country_code_picker.dart | 46 +++++++++--------------------- lib/src/country_localizations.dart | 23 +++++++++------ 3 files changed, 30 insertions(+), 40 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 9318ecb..30fe4db 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -89,6 +89,7 @@ class MyAppState extends State { ], localizationsDelegates: const [ CountryLocalizations.delegate, + /// CountryLocalizations.getDelegate(enableLocalization: false), // For no localization only english just declare delegate this way. GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, ], diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 3d6f320..c4b5260 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -152,16 +152,13 @@ class CountryCodePicker extends StatefulWidget { this.closeIcon = const Icon(Icons.close), this.countryList = codes, this.pickerStyle = PickerStyle.dialog, - 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), this.headerAlignment = MainAxisAlignment.spaceBetween, this.headerText = "Select Country", - this.headerTextStyle = - const TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + this.headerTextStyle = const TextStyle(fontSize: 18, fontWeight: FontWeight.bold), this.hideHeaderText = false, - this.topBarPadding = - const EdgeInsets.symmetric(vertical: 5.0, horizontal: 20), + this.topBarPadding = const EdgeInsets.symmetric(vertical: 5.0, horizontal: 20), Key? key, }) : super(key: key); @@ -170,16 +167,14 @@ class CountryCodePicker extends StatefulWidget { State createState() { List> jsonList = countryList; - List elements = - jsonList.map((json) => CountryCode.fromJson(json)).toList(); + List elements = jsonList.map((json) => CountryCode.fromJson(json)).toList(); if (comparator != null) { elements.sort(comparator); } if (countryFilter != null && countryFilter!.isNotEmpty) { - final uppercaseCustomList = - countryFilter!.map((criteria) => criteria.toUpperCase()).toList(); + final uppercaseCustomList = countryFilter!.map((criteria) => criteria.toUpperCase()).toList(); elements = elements .where((criteria) => uppercaseCustomList.contains(criteria.code) || @@ -205,9 +200,7 @@ class CountryCodePickerState extends State { Widget internalWidget; if (widget.builder != null) { internalWidget = InkWell( - onTap: pickerStyle == PickerStyle.dialog - ? showCountryCodePickerDialog - : showCountryCodePickerBottomSheet, + onTap: pickerStyle == PickerStyle.dialog ? showCountryCodePickerDialog : showCountryCodePickerBottomSheet, child: widget.builder!(selectedItem), ); } else { @@ -223,16 +216,12 @@ class CountryCodePickerState extends State { direction: Axis.horizontal, mainAxisSize: MainAxisSize.min, children: [ - if (widget.showFlagMain != null - ? widget.showFlagMain! - : widget.showFlag) + if (widget.showFlagMain != null ? widget.showFlagMain! : widget.showFlag) Flexible( flex: widget.alignLeft ? 0 : 1, fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, child: Container( - clipBehavior: widget.flagDecoration == null - ? Clip.none - : Clip.hardEdge, + clipBehavior: widget.flagDecoration == null ? Clip.none : Clip.hardEdge, decoration: widget.flagDecoration, margin: widget.margin ?? (widget.alignLeft @@ -249,11 +238,8 @@ class CountryCodePickerState extends State { Flexible( fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, child: Text( - widget.showOnlyCountryWhenClosed - ? selectedItem!.toCountryStringOnly() - : selectedItem.toString(), - style: widget.textStyle ?? - Theme.of(context).textTheme.labelLarge, + widget.showOnlyCountryWhenClosed ? selectedItem!.toCountryStringOnly() : selectedItem.toString(), + style: widget.textStyle ?? Theme.of(context).textTheme.labelLarge, overflow: widget.textOverflow, ), ), @@ -295,11 +281,9 @@ class CountryCodePickerState extends State { if (widget.initialSelection != null) { selectedItem = elements.firstWhere( (criteria) => - (criteria.code!.toUpperCase() == - widget.initialSelection!.toUpperCase()) || + (criteria.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) || (criteria.dialCode == widget.initialSelection) || - (criteria.name!.toUpperCase() == - widget.initialSelection!.toUpperCase()), + (criteria.name!.toUpperCase() == widget.initialSelection!.toUpperCase()), orElse: () => elements[0]); } else { selectedItem = elements[0]; @@ -315,11 +299,9 @@ class CountryCodePickerState extends State { if (widget.initialSelection != null) { selectedItem = elements.firstWhere( (item) => - (item.code!.toUpperCase() == - widget.initialSelection!.toUpperCase()) || + (item.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) || (item.dialCode == widget.initialSelection) || - (item.name!.toUpperCase() == - widget.initialSelection!.toUpperCase()), + (item.name!.toUpperCase() == widget.initialSelection!.toUpperCase()), orElse: () => elements[0]); } else { selectedItem = elements[0]; diff --git a/lib/src/country_localizations.dart b/lib/src/country_localizations.dart index ec24d2e..f0bceac 100644 --- a/lib/src/country_localizations.dart +++ b/lib/src/country_localizations.dart @@ -15,14 +15,17 @@ class CountryLocalizations { ); } - static const LocalizationsDelegate delegate = - _CountryLocalizationsDelegate(); + static const LocalizationsDelegate delegate = _CountryLocalizationsDelegate(); + + static LocalizationsDelegate getDelegate({bool enableLocalization = true}) { + return _CountryLocalizationsDelegate(enableLocalization: enableLocalization); + } late Map _localizedStrings; Future load() async { - String jsonString = await rootBundle.loadString( - 'packages/country_code_picker/src/i18n/${locale.languageCode}.json'); + String jsonString = + await rootBundle.loadString('packages/country_code_picker/src/i18n/${locale.languageCode}.json'); Map jsonMap = json.decode(jsonString); _localizedStrings = jsonMap.map((key, value) { @@ -37,9 +40,10 @@ class CountryLocalizations { } } -class _CountryLocalizationsDelegate - extends LocalizationsDelegate { - const _CountryLocalizationsDelegate(); +class _CountryLocalizationsDelegate extends LocalizationsDelegate { + final bool enableLocalization; + + const _CountryLocalizationsDelegate({this.enableLocalization = true}); @override bool isSupported(Locale locale) { @@ -119,7 +123,10 @@ class _CountryLocalizationsDelegate @override Future load(Locale locale) async { - CountryLocalizations localizations = CountryLocalizations(const Locale('en'));//locale); + // Use the provided locale if localization is enabled; otherwise, use English. + Locale effectiveLocale = enableLocalization ? locale : const Locale('en'); + + CountryLocalizations localizations = CountryLocalizations(effectiveLocale); await localizations.load(); return localizations; } From 49143d8c974d0f5a96edebf13a4abd7a174d8b78 Mon Sep 17 00:00:00 2001 From: Nilashish Roy Date: Fri, 7 Feb 2025 23:43:41 +0600 Subject: [PATCH 4/4] Added Proper documentation in Readme.md File. --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 22a3d1c..14bdce4 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,9 @@ void _onCountryChange(CountryCode countryCode) { ### i18n -Just add the `CountryLocalizations.delegate` in the list of your app delegates +Just add the `CountryLocalizations.delegate` in the list of your app delegates +### Default Usage (Localization Enabled) ```dart return new MaterialApp( supportedLocales: [ @@ -140,9 +141,19 @@ Just add the `CountryLocalizations.delegate` in the list of your app delegates ], ``` +### Force English (Localization Disabled) +```dart + return new MaterialApp( + localizationsDelegates: [ + CountryLocalizations.delegate(enableLocalization: false), + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + ], +``` + ## Customization -Here is a list of properties available to customize your widget: +Here is a list of properties available to customizeccc your widget: | Name | Type | Description | |-----|-----|------| @@ -198,7 +209,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Chandra Abdul Fattah
Chandra Abdul Fattah

🚇 💻 Salvatore Giordano
Salvatore Giordano

🚇 💻 - + Nilashish Roy
Nilashish Roy

🚇 💻 +