22 Commits
3.2.0 ... 3.4.0

Author SHA1 Message Date
Chandra Abdul Fattah
72d10bcba5 Merge pull request #65 from chandrabezzo/release-3.4.0
Some checks failed
Publish to pub.dev / publish (push) Has been cancelled
Release 3.4.0
2025-08-19 19:56:45 +07:00
Chandra Abdul Fattah
0cc1771ebf Update CHANGELOG.md 2025-08-19 19:56:28 +07:00
Chandra Abdul Fattah
864dce4d4b Update pubspec.yaml 2025-08-19 19:53:48 +07:00
Chandra Abdul Fattah
bc3cd989a4 Merge pull request #60 from ShahanMalik/patch-2
Update selection_dialog.dart
2025-08-19 19:50:36 +07:00
Chandra Abdul Fattah
f800e933ad Merge pull request #59 from ShahanMalik/patch-1
Update country_code_picker.dart
2025-08-19 19:49:45 +07:00
Chandra Abdul Fattah
c0a8a00d27 Merge pull request #57 from bailyzheng/zldev
Standardizing the description of various regions in China
2025-08-19 19:48:30 +07:00
Chandra Abdul Fattah
85f3ab6cf8 Merge pull request #63 from DomFiume/fix/dfi/french_translation
Some checks failed
Publish to pub.dev / publish (push) Has been cancelled
fix/dfi/french_translation
2025-08-19 19:37:34 +07:00
Dominique FIUME
9b71ba2931 update version number 2025-08-19 14:33:05 +02:00
Chandra Abdul Fattah
1344c6064e Merge pull request #64 from chandrabezzo/chandrabezzo-patch-1
Update dart.yml
2025-08-19 19:32:37 +07:00
Chandra Abdul Fattah
44945e23a5 Update dart.yml 2025-08-19 19:32:23 +07:00
Dominique FIUME
e7896adbd8 fixing accent removal 2025-08-19 13:53:36 +02:00
Dominique FIUME
84064c236d fix french translations 2025-08-19 11:19:10 +02:00
Shahan
0a873bd7e9 Update selection_dialog.dart
add isFocused property in textfield
2025-07-22 16:56:44 +05:00
Shahan
84673f3488 Update country_code_picker.dart
add autofocus property in textfield
2025-07-22 16:53:52 +05:00
stones
0460f3f37c Standardizing the description of various regions in China 2025-04-27 09:31:34 +08:00
Chandra Abdul Fattah
fbc4d9ea28 Merge pull request #55 from chandrabezzo/fix/version/3.3.0
Update Version 3.3.0
2025-03-26 09:05:47 +07:00
Chandra Abdul Fattah
2078ad5506 Update version 2025-03-26 09:04:27 +07:00
Chandra Abdul Fattah
4c64b01183 Merge pull request #51 from MrRoy121/main
Fix Typos, Localization Issue, and Syria Flag Issue in CountryCodePicker #50, #48, #45
2025-03-26 09:01:28 +07:00
Nilashish Roy
49143d8c97 Added Proper documentation in Readme.md File. 2025-02-07 23:43:41 +06:00
Nilashish Roy
9faf5a79cf Fixed the Issue #48.
Localization is hardcoded to english since 3.2.0 #48

Added the localization use and boolean
2025-02-07 23:00:18 +06:00
Nilashish Roy
282ed6e0be Fixed the Issue #45.
issue with syria flag #45

Updated the syrian flag
2025-02-07 21:42:27 +06:00
Nilashish Roy
3bbd4e7e62 Fixed the Issue #50.
Typo: "Country" not "County" #50

Fixed the header text getting Spelling error.
2025-02-07 21:29:56 +06:00
14 changed files with 139 additions and 101 deletions

View File

@@ -1,20 +1,19 @@
name: Publish plugin # This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Publish to pub.dev
on: on:
push: push:
tags: tags:
- v* - '[0-9]+.[0-9]+.[0-9]+*'
jobs: jobs:
publish: publish:
permissions:
runs-on: ubuntu-latest id-token: write # Required for authentication using OIDC
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
steps: # with:
- name: Checkout # working-directory: path/to/package/within/repository
uses: actions/checkout@v1
- name: Publish
uses: sakebook/actions-flutter-pub-publisher@v1.2.1
with:
credential: ${{ secrets.CREDENTIALS }}
skip_test: true

View File

@@ -1,3 +1,16 @@
## 3.4.0 - August 19 2025
- Fix China translation
- Adding flag autofocus
## 3.3.1 - August 19 2025
- Fix French translation accent display issue
- Correct French country name translations (Biélorussie, Koweït, Grenade, etc.)
- Preserve accents in displayed names while maintaining search functionality
- Update search logic to handle both accented and non-accented input
## 3.3.0 - March 26 2025
- Fix localization, typo, and flag issue #51 thanks to @MrRoy121
## 3.2.0 - January 31 2025 ## 3.2.0 - January 31 2025
- Add country code picker style #6 - Add country code picker style #6
- Remove Special Character #37 - Remove Special Character #37

View File

@@ -57,8 +57,9 @@ void _onCountryChange(CountryCode countryCode) {
### i18n ### 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 ```dart
return new MaterialApp( return new MaterialApp(
supportedLocales: [ 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 ## 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 | | Name | Type | Description |
|-----|-----|------| |-----|-----|------|
@@ -198,7 +209,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<tr> <tr>
<td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/chandra-abdul-fattah"><img src="https://avatars.githubusercontent.com/u/16184998?v=4?s=100" width="100px;" alt="Chandra Abdul Fattah"/><br /><sub><b>Chandra Abdul Fattah</b></sub></a><br /><a href="#infra-chandrabezzo" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/chandrabezzo/CountryCodePicker/commits?author=chandrabezzo" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/chandra-abdul-fattah"><img src="https://avatars.githubusercontent.com/u/16184998?v=4?s=100" width="100px;" alt="Chandra Abdul Fattah"/><br /><sub><b>Chandra Abdul Fattah</b></sub></a><br /><a href="#infra-chandrabezzo" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/chandrabezzo/CountryCodePicker/commits?author=chandrabezzo" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/imtoori"><img src="https://avatars.githubusercontent.com/u/20601437?v=4?s=100" width="100px;" alt="Salvatore Giordano"/><br /><sub><b>Salvatore Giordano</b></sub></a><br /><a href="#infra-imtoori" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/chandrabezzo/CountryCodePicker/commits?author=imtoori" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/imtoori"><img src="https://avatars.githubusercontent.com/u/20601437?v=4?s=100" width="100px;" alt="Salvatore Giordano"/><br /><sub><b>Salvatore Giordano</b></sub></a><br /><a href="#infra-imtoori" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/chandrabezzo/CountryCodePicker/commits?author=imtoori" title="Code">💻</a></td>
</tr> <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/nilashish-roy-b8a4a0171/"><img src="https://avatars.githubusercontent.com/u/96123041?v=4?s=100" width="100px;" alt="Nilashish Roy"/><br /><sub><b>Nilashish Roy</b></sub></a><br /><a href="#infra-mrroy121" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/chandrabezzo/CountryCodePicker/commits?author=mrroy121" title="Code">💻</a></td>
</tr>
</tbody> </tbody>
</table> </table>

View File

@@ -89,6 +89,7 @@ class MyAppState extends State<MyApp> {
], ],
localizationsDelegates: const [ localizationsDelegates: const [
CountryLocalizations.delegate, CountryLocalizations.delegate,
/// CountryLocalizations.getDelegate(enableLocalization: false), // For no localization only english just declare delegate this way.
GlobalMaterialLocalizations.delegate, GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate, GlobalWidgetsLocalizations.delegate,
], ],

Binary file not shown.

Before

Width:  |  Height:  |  Size: 494 B

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@@ -27,6 +27,7 @@ class CountryCodePicker extends StatefulWidget {
final bool showCountryOnly; final bool showCountryOnly;
final InputDecoration searchDecoration; final InputDecoration searchDecoration;
final TextStyle? searchStyle; final TextStyle? searchStyle;
final bool? isFocused;
final TextStyle? dialogTextStyle; final TextStyle? dialogTextStyle;
final WidgetBuilder? emptySearchBuilder; final WidgetBuilder? emptySearchBuilder;
final Function(CountryCode?)? builder; final Function(CountryCode?)? builder;
@@ -125,6 +126,7 @@ class CountryCodePicker extends StatefulWidget {
this.margin, this.margin,
this.showCountryOnly = false, this.showCountryOnly = false,
this.searchDecoration = const InputDecoration(), this.searchDecoration = const InputDecoration(),
this.isFocused = false,
this.searchStyle, this.searchStyle,
this.dialogTextStyle, this.dialogTextStyle,
this.emptySearchBuilder, this.emptySearchBuilder,
@@ -152,16 +154,13 @@ class CountryCodePicker extends StatefulWidget {
this.closeIcon = const Icon(Icons.close), this.closeIcon = const Icon(Icons.close),
this.countryList = codes, this.countryList = codes,
this.pickerStyle = PickerStyle.dialog, this.pickerStyle = PickerStyle.dialog,
this.dialogItemPadding = this.dialogItemPadding = const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
this.searchPadding = const EdgeInsets.symmetric(horizontal: 24), this.searchPadding = const EdgeInsets.symmetric(horizontal: 24),
this.headerAlignment = MainAxisAlignment.spaceBetween, this.headerAlignment = MainAxisAlignment.spaceBetween,
this.headerText = "Select County", this.headerText = "Select Country",
this.headerTextStyle = this.headerTextStyle = const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
this.hideHeaderText = false, this.hideHeaderText = false,
this.topBarPadding = this.topBarPadding = const EdgeInsets.symmetric(vertical: 5.0, horizontal: 20),
const EdgeInsets.symmetric(vertical: 5.0, horizontal: 20),
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@@ -170,16 +169,14 @@ class CountryCodePicker extends StatefulWidget {
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
List<Map<String, String>> jsonList = countryList; List<Map<String, String>> jsonList = countryList;
List<CountryCode> elements = List<CountryCode> elements = jsonList.map((json) => CountryCode.fromJson(json)).toList();
jsonList.map((json) => CountryCode.fromJson(json)).toList();
if (comparator != null) { if (comparator != null) {
elements.sort(comparator); elements.sort(comparator);
} }
if (countryFilter != null && countryFilter!.isNotEmpty) { if (countryFilter != null && countryFilter!.isNotEmpty) {
final uppercaseCustomList = final uppercaseCustomList = countryFilter!.map((criteria) => criteria.toUpperCase()).toList();
countryFilter!.map((criteria) => criteria.toUpperCase()).toList();
elements = elements elements = elements
.where((criteria) => .where((criteria) =>
uppercaseCustomList.contains(criteria.code) || uppercaseCustomList.contains(criteria.code) ||
@@ -205,9 +202,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
Widget internalWidget; Widget internalWidget;
if (widget.builder != null) { if (widget.builder != null) {
internalWidget = InkWell( internalWidget = InkWell(
onTap: pickerStyle == PickerStyle.dialog onTap: pickerStyle == PickerStyle.dialog ? showCountryCodePickerDialog : showCountryCodePickerBottomSheet,
? showCountryCodePickerDialog
: showCountryCodePickerBottomSheet,
child: widget.builder!(selectedItem), child: widget.builder!(selectedItem),
); );
} else { } else {
@@ -223,16 +218,12 @@ class CountryCodePickerState extends State<CountryCodePicker> {
direction: Axis.horizontal, direction: Axis.horizontal,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
if (widget.showFlagMain != null if (widget.showFlagMain != null ? widget.showFlagMain! : widget.showFlag)
? widget.showFlagMain!
: widget.showFlag)
Flexible( Flexible(
flex: widget.alignLeft ? 0 : 1, flex: widget.alignLeft ? 0 : 1,
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
child: Container( child: Container(
clipBehavior: widget.flagDecoration == null clipBehavior: widget.flagDecoration == null ? Clip.none : Clip.hardEdge,
? Clip.none
: Clip.hardEdge,
decoration: widget.flagDecoration, decoration: widget.flagDecoration,
margin: widget.margin ?? margin: widget.margin ??
(widget.alignLeft (widget.alignLeft
@@ -249,11 +240,8 @@ class CountryCodePickerState extends State<CountryCodePicker> {
Flexible( Flexible(
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
child: Text( child: Text(
widget.showOnlyCountryWhenClosed widget.showOnlyCountryWhenClosed ? selectedItem!.toCountryStringOnly() : selectedItem.toString(),
? selectedItem!.toCountryStringOnly() style: widget.textStyle ?? Theme.of(context).textTheme.labelLarge,
: selectedItem.toString(),
style: widget.textStyle ??
Theme.of(context).textTheme.labelLarge,
overflow: widget.textOverflow, overflow: widget.textOverflow,
), ),
), ),
@@ -295,11 +283,9 @@ class CountryCodePickerState extends State<CountryCodePicker> {
if (widget.initialSelection != null) { if (widget.initialSelection != null) {
selectedItem = elements.firstWhere( selectedItem = elements.firstWhere(
(criteria) => (criteria) =>
(criteria.code!.toUpperCase() == (criteria.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) ||
widget.initialSelection!.toUpperCase()) ||
(criteria.dialCode == widget.initialSelection) || (criteria.dialCode == widget.initialSelection) ||
(criteria.name!.toUpperCase() == (criteria.name!.toUpperCase() == widget.initialSelection!.toUpperCase()),
widget.initialSelection!.toUpperCase()),
orElse: () => elements[0]); orElse: () => elements[0]);
} else { } else {
selectedItem = elements[0]; selectedItem = elements[0];
@@ -315,11 +301,9 @@ class CountryCodePickerState extends State<CountryCodePicker> {
if (widget.initialSelection != null) { if (widget.initialSelection != null) {
selectedItem = elements.firstWhere( selectedItem = elements.firstWhere(
(item) => (item) =>
(item.code!.toUpperCase() == (item.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) ||
widget.initialSelection!.toUpperCase()) ||
(item.dialCode == widget.initialSelection) || (item.dialCode == widget.initialSelection) ||
(item.name!.toUpperCase() == (item.name!.toUpperCase() == widget.initialSelection!.toUpperCase()),
widget.initialSelection!.toUpperCase()),
orElse: () => elements[0]); orElse: () => elements[0]);
} else { } else {
selectedItem = elements[0]; selectedItem = elements[0];
@@ -348,6 +332,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
emptySearchBuilder: widget.emptySearchBuilder, emptySearchBuilder: widget.emptySearchBuilder,
searchDecoration: widget.searchDecoration, searchDecoration: widget.searchDecoration,
searchStyle: widget.searchStyle, searchStyle: widget.searchStyle,
isFocused: widget.isFocused,
textStyle: widget.dialogTextStyle, textStyle: widget.dialogTextStyle,
boxDecoration: widget.boxDecoration, boxDecoration: widget.boxDecoration,
showFlag: widget.showFlagDialog ?? widget.showFlag, showFlag: widget.showFlagDialog ?? widget.showFlag,

View File

@@ -1,5 +1,4 @@
import 'package:collection/collection.dart' show IterableExtension; import 'package:collection/collection.dart' show IterableExtension;
import 'package:diacritic/diacritic.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart' show kDebugMode; import 'package:flutter/foundation.dart' show kDebugMode;
@@ -45,7 +44,9 @@ class CountryCode {
try { try {
return CountryCode.fromCountryCode(countryCode); return CountryCode.fromCountryCode(countryCode);
} catch (e) { } catch (e) {
if (kDebugMode) print('Failed to recognize country from countryCode: $countryCode'); if (kDebugMode) {
print('Failed to recognize country from countryCode: $countryCode');
}
return null; return null;
} }
} }
@@ -61,20 +62,21 @@ class CountryCode {
try { try {
return CountryCode.fromDialCode(dialCode); return CountryCode.fromDialCode(dialCode);
} catch (e) { } catch (e) {
if (kDebugMode) print('Failed to recognize country from dialCode: $dialCode'); if (kDebugMode) {
print('Failed to recognize country from dialCode: $dialCode');
}
return null; return null;
} }
} }
CountryCode localize(BuildContext context) { CountryCode localize(BuildContext context) {
final nam = CountryLocalizations.of(context)?.translate(code) ?? name; final nam = CountryLocalizations.of(context)?.translate(code) ?? name;
return this return this..name = nam ?? name;
..name = nam == null? name : removeDiacritics(nam);
} }
factory CountryCode.fromJson(Map<String, dynamic> json) { factory CountryCode.fromJson(Map<String, dynamic> json) {
return CountryCode( return CountryCode(
name: removeDiacritics(json['name']), name: json['name'],
code: json['code'], code: json['code'],
dialCode: json['dial_code'], dialCode: json['dial_code'],
flagUri: 'flags/${json['code'].toLowerCase()}.png', flagUri: 'flags/${json['code'].toLowerCase()}.png',

View File

@@ -83,7 +83,7 @@ const List<Map<String, String>> codes = [
}, },
{"name": "Tchad", "code": "TD", "iso3Code": "TCD", "dial_code": "+235"}, {"name": "Tchad", "code": "TD", "iso3Code": "TCD", "dial_code": "+235"},
{"name": "Chile", "code": "CL", "iso3Code": "CHL", "dial_code": "+56"}, {"name": "Chile", "code": "CL", "iso3Code": "CHL", "dial_code": "+56"},
{"name": "中国", "code": "CN", "iso3Code": "CHN", "dial_code": "+86"}, {"name": "中国大陆", "code": "CN", "iso3Code": "CHN", "dial_code": "+86"},
{ {
"name": "Christmas Island", "name": "Christmas Island",
"code": "CX", "code": "CX",
@@ -216,7 +216,7 @@ const List<Map<String, String>> codes = [
}, },
{"name": "Vaticano", "code": "VA", "iso3Code": "VAT", "dial_code": "+379"}, {"name": "Vaticano", "code": "VA", "iso3Code": "VAT", "dial_code": "+379"},
{"name": "Honduras", "code": "HN", "iso3Code": "HND", "dial_code": "+504"}, {"name": "Honduras", "code": "HN", "iso3Code": "HND", "dial_code": "+504"},
{"name": "香港", "code": "HK", "iso3Code": "HKG", "dial_code": "+852"}, {"name": "中國香港", "code": "HK", "iso3Code": "HKG", "dial_code": "+852"},
{"name": "Magyarország", "code": "HU", "iso3Code": "HUN", "dial_code": "+36"}, {"name": "Magyarország", "code": "HU", "iso3Code": "HUN", "dial_code": "+36"},
{"name": "Ísland", "code": "IS", "iso3Code": "ISL", "dial_code": "+354"}, {"name": "Ísland", "code": "IS", "iso3Code": "ISL", "dial_code": "+354"},
{"name": "भारत", "code": "IN", "iso3Code": "IND", "dial_code": "+91"}, {"name": "भारत", "code": "IN", "iso3Code": "IND", "dial_code": "+91"},
@@ -258,7 +258,7 @@ const List<Map<String, String>> codes = [
}, },
{"name": "Lietuva", "code": "LT", "iso3Code": "LTU", "dial_code": "+370"}, {"name": "Lietuva", "code": "LT", "iso3Code": "LTU", "dial_code": "+370"},
{"name": "Luxembourg", "code": "LU", "iso3Code": "LUX", "dial_code": "+352"}, {"name": "Luxembourg", "code": "LU", "iso3Code": "LUX", "dial_code": "+352"},
{"name": "澳門", "code": "MO", "iso3Code": "MAC", "dial_code": "+853"}, {"name": "中國澳門", "code": "MO", "iso3Code": "MAC", "dial_code": "+853"},
{"name": "Македонија", "code": "MK", "iso3Code": "MKD", "dial_code": "+389"}, {"name": "Македонија", "code": "MK", "iso3Code": "MKD", "dial_code": "+389"},
{ {
"name": "Madagasikara", "name": "Madagasikara",
@@ -456,7 +456,7 @@ const List<Map<String, String>> codes = [
{"name": "Sverige", "code": "SE", "iso3Code": "SWE", "dial_code": "+46"}, {"name": "Sverige", "code": "SE", "iso3Code": "SWE", "dial_code": "+46"},
{"name": "Schweiz", "code": "CH", "iso3Code": "CHE", "dial_code": "+41"}, {"name": "Schweiz", "code": "CH", "iso3Code": "CHE", "dial_code": "+41"},
{"name": "سوريا", "code": "SY", "iso3Code": "SYR", "dial_code": "+963"}, {"name": "سوريا", "code": "SY", "iso3Code": "SYR", "dial_code": "+963"},
{"name": "臺灣", "code": "TW", "iso3Code": "TWN", "dial_code": "+886"}, {"name": "中國臺灣", "code": "TW", "iso3Code": "TWN", "dial_code": "+886"},
{"name": "Тоҷикистон", "code": "TJ", "iso3Code": "TJK", "dial_code": "+992"}, {"name": "Тоҷикистон", "code": "TJ", "iso3Code": "TJK", "dial_code": "+992"},
{"name": "Tanzania", "code": "TZ", "iso3Code": "TZA", "dial_code": "+255"}, {"name": "Tanzania", "code": "TZ", "iso3Code": "TZA", "dial_code": "+255"},
{"name": "ประเทศไทย", "code": "TH", "iso3Code": "THA", "dial_code": "+66"}, {"name": "ประเทศไทย", "code": "TH", "iso3Code": "THA", "dial_code": "+66"},

View File

@@ -15,14 +15,17 @@ class CountryLocalizations {
); );
} }
static const LocalizationsDelegate<CountryLocalizations> delegate = static const LocalizationsDelegate<CountryLocalizations> delegate = _CountryLocalizationsDelegate();
_CountryLocalizationsDelegate();
static LocalizationsDelegate<CountryLocalizations> getDelegate({bool enableLocalization = true}) {
return _CountryLocalizationsDelegate(enableLocalization: enableLocalization);
}
late Map<String, String> _localizedStrings; late Map<String, String> _localizedStrings;
Future<bool> load() async { Future<bool> load() async {
String jsonString = await rootBundle.loadString( String jsonString =
'packages/country_code_picker/src/i18n/${locale.languageCode}.json'); await rootBundle.loadString('packages/country_code_picker/src/i18n/${locale.languageCode}.json');
Map<String, dynamic> jsonMap = json.decode(jsonString); Map<String, dynamic> jsonMap = json.decode(jsonString);
_localizedStrings = jsonMap.map((key, value) { _localizedStrings = jsonMap.map((key, value) {
@@ -37,9 +40,10 @@ class CountryLocalizations {
} }
} }
class _CountryLocalizationsDelegate class _CountryLocalizationsDelegate extends LocalizationsDelegate<CountryLocalizations> {
extends LocalizationsDelegate<CountryLocalizations> { final bool enableLocalization;
const _CountryLocalizationsDelegate();
const _CountryLocalizationsDelegate({this.enableLocalization = true});
@override @override
bool isSupported(Locale locale) { bool isSupported(Locale locale) {
@@ -119,7 +123,10 @@ class _CountryLocalizationsDelegate
@override @override
Future<CountryLocalizations> load(Locale locale) async { Future<CountryLocalizations> 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(); await localizations.load();
return localizations; return localizations;
} }

View File

@@ -42,7 +42,7 @@
"CF": "Central African Republic", "CF": "Central African Republic",
"TD": "Chad", "TD": "Chad",
"CL": "Chile", "CL": "Chile",
"CN": "China", "CN": "China's Mainland",
"CX": "Christmas Island", "CX": "Christmas Island",
"CC": "Cocos (Keeling) Islands", "CC": "Cocos (Keeling) Islands",
"CO": "Colombia", "CO": "Colombia",
@@ -94,7 +94,7 @@
"HM": "Heard Island and McDonald Islands", "HM": "Heard Island and McDonald Islands",
"VA": "Holy See (Vatican City State)", "VA": "Holy See (Vatican City State)",
"HN": "Honduras", "HN": "Honduras",
"HK": "Hong Kong", "HK": "Hong Kong China",
"HU": "Hungary", "HU": "Hungary",
"IS": "Iceland", "IS": "Iceland",
"IN": "India", "IN": "India",
@@ -123,7 +123,7 @@
"LI": "Liechtenstein", "LI": "Liechtenstein",
"LT": "Lithuania", "LT": "Lithuania",
"LU": "Luxembourg", "LU": "Luxembourg",
"MO": "Macao", "MO": "Macao China",
"MG": "Madagascar", "MG": "Madagascar",
"MW": "Malawi", "MW": "Malawi",
"MY": "Malaysia", "MY": "Malaysia",
@@ -210,10 +210,7 @@
"SE": "Sweden", "SE": "Sweden",
"CH": "Switzerland", "CH": "Switzerland",
"SY": "Syrian Arab Republic", "SY": "Syrian Arab Republic",
"TW": [ "TW": "Taiwan China",
"Taiwan, Province of China",
"Taiwan"
],
"TJ": "Tajikistan", "TJ": "Tajikistan",
"TZ": "Tanzania, United Republic of", "TZ": "Tanzania, United Republic of",
"TH": "Thailand", "TH": "Thailand",

View File

@@ -18,7 +18,7 @@
"BH": "Bahrein", "BH": "Bahrein",
"BD": "Bangladesh", "BD": "Bangladesh",
"BB": "Barbade", "BB": "Barbade",
"BY": "Bielorussie", "BY": "Biélorussie",
"BE": "Belgique", "BE": "Belgique",
"BZ": "Belize", "BZ": "Belize",
"BJ": "Bénin", "BJ": "Bénin",
@@ -38,7 +38,7 @@
"CM": "Cameroun", "CM": "Cameroun",
"CA": "Canada", "CA": "Canada",
"CV": "Cap-Vert", "CV": "Cap-Vert",
"KY": "Caïmanes", "KY": "Îles Caïmans",
"CF": "Centrafricaine, République", "CF": "Centrafricaine, République",
"TD": "Tchad", "TD": "Tchad",
"CL": "Chili", "CL": "Chili",
@@ -83,7 +83,7 @@
"GI": "Gibraltar", "GI": "Gibraltar",
"GR": "Grèce", "GR": "Grèce",
"GL": "Groenland", "GL": "Groenland",
"GD": "Grenada", "GD": "Grenade",
"GP": "Guadeloupe", "GP": "Guadeloupe",
"GU": "Guam", "GU": "Guam",
"GT": "Guatemala", "GT": "Guatemala",
@@ -110,9 +110,9 @@
"KZ": "Kazakhstan", "KZ": "Kazakhstan",
"KE": "Kenya", "KE": "Kenya",
"KI": "Kiribati", "KI": "Kiribati",
"KP": "Corée du Nord, République populaire démocratique", "KP": "Corée du Nord",
"KR": "Corée du Sud, République", "KR": "Corée du Sud",
"KW": "Koweit", "KW": "Koweït",
"KG": "Kirghistan", "KG": "Kirghistan",
"LA": "Laos", "LA": "Laos",
"LV": "Lettonie", "LV": "Lettonie",
@@ -179,7 +179,7 @@
"SH": "Sainte-Hélène", "SH": "Sainte-Hélène",
"KN": "Saint-Christophe-et-Niévès", "KN": "Saint-Christophe-et-Niévès",
"LC": "Sainte-Lucie", "LC": "Sainte-Lucie",
"PM": "Saint Pierre and Miquelon", "PM": "Saint-Pierre-et-Miquelon",
"VC": "Saint-Vincent et les Grenadines", "VC": "Saint-Vincent et les Grenadines",
"WS": "Samoa", "WS": "Samoa",
"SM": "Saint-Marin", "SM": "Saint-Marin",
@@ -200,15 +200,15 @@
"SD": "Soudan", "SD": "Soudan",
"SR": "Suriname", "SR": "Suriname",
"SJ": "Svalbard et Île Jan Mayen", "SJ": "Svalbard et Île Jan Mayen",
"SZ": "Ngwane, Royaume d'Eswatini", "SZ": "Eswatini",
"SE": "Suède", "SE": "Suède",
"CH": "Suisse", "CH": "Suisse",
"SY": "Syrie", "SY": "Syrie",
"TW": "Taïwan", "TW": "Taïwan",
"TJ": "Tadjikistan", "TJ": "Tadjikistan",
"TZ": "Tanzanie, République unie", "TZ": "Tanzanie",
"TH": "Thaïlande", "TH": "Thaïlande",
"TL": "Timor Leste", "TL": "Timor-Leste",
"TG": "Togo", "TG": "Togo",
"TK": "Tokelau", "TK": "Tokelau",
"TO": "Tonga", "TO": "Tonga",

View File

@@ -46,7 +46,7 @@
"CK": "库克群岛", "CK": "库克群岛",
"CL": "智利", "CL": "智利",
"CM": "喀麦隆", "CM": "喀麦隆",
"CN": "中国", "CN": "中国大陆",
"CO": "哥伦比亚", "CO": "哥伦比亚",
"CR": "哥斯达黎加", "CR": "哥斯达黎加",
"CU": "古巴", "CU": "古巴",
@@ -93,7 +93,7 @@
"GU": "关岛", "GU": "关岛",
"GW": "几内亚比绍", "GW": "几内亚比绍",
"GY": "圭亚那", "GY": "圭亚那",
"HK": "香港", "HK": "中国香港",
"HM": "赫德岛和麦克唐纳群岛", "HM": "赫德岛和麦克唐纳群岛",
"HN": "洪都拉斯", "HN": "洪都拉斯",
"HR": "克罗地亚", "HR": "克罗地亚",
@@ -146,7 +146,7 @@
"ML": "马里", "ML": "马里",
"MM": "缅甸", "MM": "缅甸",
"MN": "蒙古", "MN": "蒙古",
"MO": "澳门", "MO": "中国澳门",
"MP": "北马里亚纳群岛", "MP": "北马里亚纳群岛",
"MQ": "马提尼克", "MQ": "马提尼克",
"MR": "毛里塔尼亚", "MR": "毛里塔尼亚",
@@ -226,7 +226,7 @@
"TR": "土耳其", "TR": "土耳其",
"TT": "特立尼达和多巴哥", "TT": "特立尼达和多巴哥",
"TV": "图瓦卢", "TV": "图瓦卢",
"TW": "中国台湾", "TW": "中国台湾",
"TZ": "坦桑尼亚", "TZ": "坦桑尼亚",
"UA": "乌克兰", "UA": "乌克兰",
"UG": "乌干达", "UG": "乌干达",

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:diacritic/diacritic.dart';
import 'country_code.dart'; import 'country_code.dart';
import 'country_localizations.dart'; import 'country_localizations.dart';
@@ -9,6 +10,7 @@ class SelectionDialog extends StatefulWidget {
final bool? showCountryOnly; final bool? showCountryOnly;
final InputDecoration searchDecoration; final InputDecoration searchDecoration;
final TextStyle? searchStyle; final TextStyle? searchStyle;
final bool? isFocused;
final TextStyle? textStyle; final TextStyle? textStyle;
final TextStyle headerTextStyle; final TextStyle headerTextStyle;
final BoxDecoration? boxDecoration; final BoxDecoration? boxDecoration;
@@ -49,8 +51,9 @@ class SelectionDialog extends StatefulWidget {
required this.headerTextStyle, required this.headerTextStyle,
InputDecoration searchDecoration = const InputDecoration(), InputDecoration searchDecoration = const InputDecoration(),
this.searchStyle, this.searchStyle,
this.isFocused,
this.textStyle, this.textStyle,
required this.topBarPadding, required this.topBarPadding,
this.headerText, this.headerText,
this.boxDecoration, this.boxDecoration,
this.showFlag, this.showFlag,
@@ -62,9 +65,12 @@ class SelectionDialog extends StatefulWidget {
this.hideSearch = false, this.hideSearch = false,
this.hideCloseIcon = false, this.hideCloseIcon = false,
this.closeIcon, this.closeIcon,
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.searchPadding = const EdgeInsets.symmetric(horizontal: 24),
}) : searchDecoration = searchDecoration.prefixIcon == null ? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search)) : searchDecoration, }) : searchDecoration = searchDecoration.prefixIcon == null
? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search))
: searchDecoration,
super(key: key); super(key: key);
@override @override
@@ -81,7 +87,8 @@ class _SelectionDialogState extends State<SelectionDialog> {
child: Container( child: Container(
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
width: widget.size?.width ?? MediaQuery.of(context).size.width, width: widget.size?.width ?? MediaQuery.of(context).size.width,
height: widget.size?.height ?? MediaQuery.of(context).size.height * 0.85, height:
widget.size?.height ?? MediaQuery.of(context).size.height * 0.85,
decoration: widget.boxDecoration ?? decoration: widget.boxDecoration ??
BoxDecoration( BoxDecoration(
color: widget.backgroundColor ?? Colors.white, color: widget.backgroundColor ?? Colors.white,
@@ -100,7 +107,9 @@ class _SelectionDialogState extends State<SelectionDialog> {
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
Padding( Padding(
padding:!widget.hideHeaderText? widget.topBarPadding: EdgeInsets.zero, padding: !widget.hideHeaderText
? widget.topBarPadding
: EdgeInsets.zero,
child: Row( child: Row(
mainAxisAlignment: widget.headerAlignment, mainAxisAlignment: widget.headerAlignment,
children: [ children: [
@@ -125,6 +134,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
Padding( Padding(
padding: widget.searchPadding, padding: widget.searchPadding,
child: TextField( child: TextField(
autofocus: widget.isFocused ?? false,
style: widget.searchStyle, style: widget.searchStyle,
decoration: widget.searchDecoration, decoration: widget.searchDecoration,
onChanged: _filterElements, onChanged: _filterElements,
@@ -177,11 +187,14 @@ class _SelectionDialogState extends State<SelectionDialog> {
if (widget.showFlag!) if (widget.showFlag!)
Flexible( Flexible(
child: Container( child: Container(
margin: Directionality.of(context) == TextDirection.ltr // Here Adding padding depending on the locale language direction margin: Directionality.of(context) ==
TextDirection
.ltr // Here Adding padding depending on the locale language direction
? const EdgeInsets.only(right: 16.0) ? const EdgeInsets.only(right: 16.0)
: const EdgeInsets.only(left: 16.0), : const EdgeInsets.only(left: 16.0),
decoration: widget.flagDecoration, decoration: widget.flagDecoration,
clipBehavior: widget.flagDecoration == null ? Clip.none : Clip.hardEdge, clipBehavior:
widget.flagDecoration == null ? Clip.none : Clip.hardEdge,
child: Image.asset( child: Image.asset(
e.flagUri!, e.flagUri!,
package: 'country_code_picker', package: 'country_code_picker',
@@ -192,7 +205,9 @@ class _SelectionDialogState extends State<SelectionDialog> {
Expanded( Expanded(
flex: 4, flex: 4,
child: Text( child: Text(
widget.showCountryOnly! ? e.toCountryStringOnly() : e.toLongString(), widget.showCountryOnly!
? e.toCountryStringOnly()
: e.toLongString(),
overflow: TextOverflow.fade, overflow: TextOverflow.fade,
style: widget.textStyle, style: widget.textStyle,
), ),
@@ -208,7 +223,8 @@ class _SelectionDialogState extends State<SelectionDialog> {
} }
return Center( return Center(
child: Text(CountryLocalizations.of(context)?.translate('no_country') ?? 'No country found'), child: Text(CountryLocalizations.of(context)?.translate('no_country') ??
'No country found'),
); );
} }
@@ -219,9 +235,15 @@ class _SelectionDialogState extends State<SelectionDialog> {
} }
void _filterElements(String s) { void _filterElements(String s) {
s = s.toUpperCase(); final normalizedSearch = removeDiacritics(s.toUpperCase());
setState(() { setState(() {
filteredElements = widget.elements.where((e) => e.code!.contains(s) || e.dialCode!.contains(s) || e.name!.toUpperCase().contains(s)).toList(); filteredElements = widget.elements
.where((e) =>
e.code!.contains(normalizedSearch) ||
e.dialCode!.contains(normalizedSearch) ||
removeDiacritics(e.name!.toUpperCase())
.contains(normalizedSearch))
.toList();
}); });
} }

View File

@@ -1,6 +1,6 @@
name: country_code_picker 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 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: 3.2.0 version: 3.4.0
homepage: https://github.com/chandrabezzo/CountryCodePicker homepage: https://github.com/chandrabezzo/CountryCodePicker
repository: https://github.com/chandrabezzo/CountryCodePicker repository: https://github.com/chandrabezzo/CountryCodePicker
issue_tracker: https://github.com/imtoori/CountryCodePicker/issues issue_tracker: https://github.com/imtoori/CountryCodePicker/issues