Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -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:
push:
tags:
- v*
tags:
- '[0-9]+.[0-9]+.[0-9]+*'

jobs:
publish:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1
- name: Publish
uses: sakebook/actions-flutter-pub-publisher@v1.2.1
with:
credential: ${{ secrets.CREDENTIALS }}
skip_test: true
permissions:
id-token: write # Required for authentication using OIDC
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
# with:
# working-directory: path/to/package/within/repository
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 3.4.1 - October 08 2025
- Fix French country translations
- Removed Netherlands Antilles from country codes list

## 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

Expand Down
213 changes: 133 additions & 80 deletions lib/country_code_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import 'src/country_code.dart';
import 'src/country_codes.dart';
import 'src/selection_dialog.dart';

export 'src/bottom_sheet.dart';
export 'src/constants.dart';
export 'src/country_code.dart';
export 'src/country_codes.dart';
export 'src/country_localizations.dart';
export 'src/selection_dialog.dart';
export 'src/bottom_sheet.dart';
export 'src/constants.dart';

class CountryCodePicker extends StatefulWidget {
final ValueChanged<CountryCode>? onChanged;
Expand All @@ -27,6 +27,7 @@ class CountryCodePicker extends StatefulWidget {
final bool showCountryOnly;
final InputDecoration searchDecoration;
final TextStyle? searchStyle;
final bool? isFocused;
final TextStyle? dialogTextStyle;
final WidgetBuilder? emptySearchBuilder;
final Function(CountryCode?)? builder;
Expand Down Expand Up @@ -115,6 +116,20 @@ class CountryCodePicker extends StatefulWidget {
///Header Text Alignment
final MainAxisAlignment headerAlignment;

/// space after dropdown icon if shown
final double? spaceAfterDropdownIcon;

/// This function will receive the child and show a custom
/// dialog based on the function implementation
/// Note: You have to return this function to back to the package to select the country
final Function? showDialogCustomFunction;

/// This function will receive the child and show a custom
/// modal bottom sheet based on the function implementation
/// Note: You have to return this function to back to the package to select the country

final Function? showBottomSheetCustomFunction;

const CountryCodePicker({
this.onChanged,
this.onInit,
Expand All @@ -125,6 +140,7 @@ class CountryCodePicker extends StatefulWidget {
this.margin,
this.showCountryOnly = false,
this.searchDecoration = const InputDecoration(),
this.isFocused = false,
this.searchStyle,
this.dialogTextStyle,
this.emptySearchBuilder,
Expand Down Expand Up @@ -152,13 +168,19 @@ 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),
this.spaceAfterDropdownIcon,
this.showDialogCustomFunction,
this.showBottomSheetCustomFunction,
Key? key,
}) : super(key: key);

Expand All @@ -167,14 +189,16 @@ class CountryCodePicker extends StatefulWidget {
State<StatefulWidget> createState() {
List<Map<String, String>> jsonList = countryList;

List<CountryCode> elements = jsonList.map((json) => CountryCode.fromJson(json)).toList();
List<CountryCode> 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) ||
Expand All @@ -200,28 +224,37 @@ class CountryCodePickerState extends State<CountryCodePicker> {
Widget internalWidget;
if (widget.builder != null) {
internalWidget = InkWell(
onTap: pickerStyle == PickerStyle.dialog ? showCountryCodePickerDialog : showCountryCodePickerBottomSheet,
onTap: pickerStyle == PickerStyle.dialog
? () => showCountryCodePickerDialog(widget.showDialogCustomFunction)
: () => showCountryCodePickerBottomSheet(
widget.showBottomSheetCustomFunction),
child: widget.builder!(selectedItem),
);
} else {
internalWidget = TextButton(
onPressed: widget.enabled
? pickerStyle == PickerStyle.dialog
? showCountryCodePickerDialog
: showCountryCodePickerBottomSheet
? () =>
showCountryCodePickerDialog(widget.showDialogCustomFunction)
: () => showCountryCodePickerBottomSheet(
widget.showBottomSheetCustomFunction)
: null,
child: Padding(
padding: widget.padding,
child: Flex(
direction: Axis.horizontal,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
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
Expand All @@ -238,8 +271,11 @@ class CountryCodePickerState extends State<CountryCodePicker> {
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,
),
),
Expand All @@ -249,8 +285,11 @@ class CountryCodePickerState extends State<CountryCodePicker> {
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
child: Padding(
padding: (widget.alignLeft
? const EdgeInsets.only(right: 16.0, left: 8.0)
: const EdgeInsets.only(right: 16.0)),
? EdgeInsets.only(
right: widget.spaceAfterDropdownIcon ?? 16.0,
left: 8.0)
: EdgeInsets.only(
right: widget.spaceAfterDropdownIcon ?? 16.0)),
child: Icon(
Icons.arrow_drop_down,
color: Colors.grey,
Expand Down Expand Up @@ -281,9 +320,11 @@ class CountryCodePickerState extends State<CountryCodePicker> {
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];
Expand All @@ -299,9 +340,11 @@ class CountryCodePickerState extends State<CountryCodePicker> {
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];
Expand All @@ -317,41 +360,45 @@ class CountryCodePickerState extends State<CountryCodePicker> {
.toList();
}

void showCountryCodePickerDialog() async {
final item = await showDialog(
barrierColor: widget.barrierColor ?? Colors.grey.withAlpha(128),
context: context,
builder: (context) => Center(
child: Dialog(
child: SelectionDialog(
elements,
favoriteElements,
showCountryOnly: widget.showCountryOnly,
emptySearchBuilder: widget.emptySearchBuilder,
searchDecoration: widget.searchDecoration,
searchStyle: widget.searchStyle,
textStyle: widget.dialogTextStyle,
boxDecoration: widget.boxDecoration,
showFlag: widget.showFlagDialog ?? widget.showFlag,
flagWidth: widget.flagWidth,
size: widget.dialogSize,
headerAlignment: widget.headerAlignment,
headerText: widget.headerText,
headerTextStyle: widget.headerTextStyle,
hideHeaderText: widget.hideHeaderText,
topBarPadding: widget.topBarPadding,
backgroundColor: widget.dialogBackgroundColor,
barrierColor: widget.barrierColor,
hideSearch: widget.hideSearch,
hideCloseIcon: widget.hideCloseIcon,
closeIcon: widget.closeIcon,
flagDecoration: widget.flagDecoration,
dialogItemPadding: widget.dialogItemPadding,
searchPadding: widget.searchPadding,
),
),
),
void showCountryCodePickerDialog(Function? showDialogCustomFunction) async {
late final childWidget = SelectionDialog(
elements,
favoriteElements,
showCountryOnly: widget.showCountryOnly,
emptySearchBuilder: widget.emptySearchBuilder,
searchDecoration: widget.searchDecoration,
searchStyle: widget.searchStyle,
isFocused: widget.isFocused,
textStyle: widget.dialogTextStyle,
boxDecoration: widget.boxDecoration,
showFlag: widget.showFlagDialog ?? widget.showFlag,
flagWidth: widget.flagWidth,
size: widget.dialogSize,
headerAlignment: widget.headerAlignment,
headerText: widget.headerText,
headerTextStyle: widget.headerTextStyle,
hideHeaderText: widget.hideHeaderText,
topBarPadding: widget.topBarPadding,
backgroundColor: widget.dialogBackgroundColor,
barrierColor: widget.barrierColor,
hideSearch: widget.hideSearch,
hideCloseIcon: widget.hideCloseIcon,
closeIcon: widget.closeIcon,
flagDecoration: widget.flagDecoration,
dialogItemPadding: widget.dialogItemPadding,
searchPadding: widget.searchPadding,
);
final item = showDialogCustomFunction == null
? await showDialog(
barrierColor: widget.barrierColor ?? Colors.grey.withAlpha(128),
context: context,
builder: (context) => Center(
child: Dialog(
child: childWidget,
),
),
)
: await showDialogCustomFunction(context, childWidget);

if (item != null) {
setState(() {
Expand All @@ -362,33 +409,39 @@ class CountryCodePickerState extends State<CountryCodePicker> {
}
}

void showCountryCodePickerBottomSheet() async {
final item = await showModalBottomSheet(
isScrollControlled: true,
context: context,
backgroundColor: Colors.transparent,
elevation: 0,
builder: (ctx) {
return SelectionBottomSheet(
elements,
favoriteElements,
showCountryOnly: widget.showCountryOnly,
emptySearchBuilder: widget.emptySearchBuilder,
searchDecoration: widget.searchDecoration,
searchStyle: widget.searchStyle,
textStyle: widget.dialogTextStyle,
boxDecoration: widget.boxDecoration,
showFlag: widget.showFlagDialog ?? widget.showFlag,
flagWidth: widget.flagWidth,
size: widget.dialogSize,
backgroundColor: widget.dialogBackgroundColor,
barrierColor: widget.barrierColor,
hideSearch: widget.hideSearch,
closeIcon: widget.closeIcon,
flagDecoration: widget.flagDecoration,
);
},
void showCountryCodePickerBottomSheet(
Function? showBottomSheetCustomFunction) async {
//
late final sheetWidget = SelectionBottomSheet(
elements,
favoriteElements,
showCountryOnly: widget.showCountryOnly,
emptySearchBuilder: widget.emptySearchBuilder,
searchDecoration: widget.searchDecoration,
searchStyle: widget.searchStyle,
textStyle: widget.dialogTextStyle,
boxDecoration: widget.boxDecoration,
showFlag: widget.showFlagDialog ?? widget.showFlag,
flagWidth: widget.flagWidth,
size: widget.dialogSize,
backgroundColor: widget.dialogBackgroundColor,
barrierColor: widget.barrierColor,
hideSearch: widget.hideSearch,
closeIcon: widget.closeIcon,
flagDecoration: widget.flagDecoration,
);
//
final item = showBottomSheetCustomFunction == null
? await showModalBottomSheet(
isScrollControlled: true,
context: context,
backgroundColor: Colors.transparent,
elevation: 0,
builder: (ctx) {
return sheetWidget;
},
)
: await showBottomSheetCustomFunction(context, sheetWidget);

if (item == null) return;

Expand Down
Loading