Compare commits
8 Commits
3.2.0
...
fix/versio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ce3306e1f | ||
|
|
13e437d81b | ||
|
|
2078ad5506 | ||
|
|
4c64b01183 | ||
|
|
49143d8c97 | ||
|
|
9faf5a79cf | ||
|
|
282ed6e0be | ||
|
|
3bbd4e7e62 |
@@ -1,3 +1,6 @@
|
|||||||
|
## 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
|
||||||
|
|||||||
18
README.md
18
README.md
@@ -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>
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
],
|
],
|
||||||
|
|||||||
BIN
flags/sy.png
BIN
flags/sy.png
Binary file not shown.
|
Before Width: | Height: | Size: 494 B After Width: | Height: | Size: 2.4 KiB |
@@ -152,16 +152,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 +167,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 +200,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 +216,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 +238,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 +281,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 +299,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];
|
||||||
@@ -404,6 +386,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
|||||||
hideSearch: widget.hideSearch,
|
hideSearch: widget.hideSearch,
|
||||||
closeIcon: widget.closeIcon,
|
closeIcon: widget.closeIcon,
|
||||||
flagDecoration: widget.flagDecoration,
|
flagDecoration: widget.flagDecoration,
|
||||||
|
searchPadding: widget.searchPadding,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ class SelectionBottomSheet extends StatefulWidget {
|
|||||||
/// elements passed as favorite
|
/// elements passed as favorite
|
||||||
final List<CountryCode> favoriteElements;
|
final List<CountryCode> favoriteElements;
|
||||||
|
|
||||||
|
final EdgeInsetsGeometry searchPadding;
|
||||||
|
|
||||||
SelectionBottomSheet(
|
SelectionBottomSheet(
|
||||||
this.elements,
|
this.elements,
|
||||||
this.favoriteElements, {
|
this.favoriteElements, {
|
||||||
@@ -46,6 +48,7 @@ class SelectionBottomSheet extends StatefulWidget {
|
|||||||
this.barrierColor,
|
this.barrierColor,
|
||||||
this.hideSearch = false,
|
this.hideSearch = false,
|
||||||
this.closeIcon,
|
this.closeIcon,
|
||||||
|
this.searchPadding = const EdgeInsets.symmetric(horizontal: 24),
|
||||||
}) : searchDecoration = searchDecoration.prefixIcon == null
|
}) : searchDecoration = searchDecoration.prefixIcon == null
|
||||||
? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search))
|
? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search))
|
||||||
: searchDecoration,
|
: searchDecoration,
|
||||||
@@ -93,7 +96,7 @@ class _SelectionBottomSheetState extends State<SelectionBottomSheet> {
|
|||||||
),
|
),
|
||||||
if (!widget.hideSearch)
|
if (!widget.hideSearch)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
padding: widget.searchPadding,
|
||||||
child: TextField(
|
child: TextField(
|
||||||
style: widget.searchStyle,
|
style: widget.searchStyle,
|
||||||
decoration: widget.searchDecoration,
|
decoration: widget.searchDecoration,
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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": "毛里塔尼亚",
|
||||||
|
|||||||
@@ -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.3.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
|
||||||
|
|||||||
Reference in New Issue
Block a user