From 7f36d14ba6ace38dc3cc6a78d3c02bd75d73dae7 Mon Sep 17 00:00:00 2001 From: Chandra Abdul Fattah Date: Fri, 31 Jan 2025 23:26:32 +0700 Subject: [PATCH] update --- CHANGELOG.md | 5 +++ lib/country_code_picker.dart | 67 +++++++++++++++++++++++++---------- lib/src/bottom_sheet.dart | 3 +- lib/src/selection_dialog.dart | 2 +- pubspec.yaml | 8 ++--- 5 files changed, 60 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed813ed..6882d55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.2.0 - January 31 2025 +- Add country code picker style #6 +- Remove Special Character #37 +- Fixes for Flutter and Dart SDK Updates and Enhancements #44 + ## 3.1.0 - October 24 2024 - Add some improvement diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 923a352..52436aa 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -152,13 +152,16 @@ 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 County", - 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); @@ -167,15 +170,22 @@ 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(); - elements = elements.where((criteria) => uppercaseCustomList.contains(criteria.code) || uppercaseCustomList.contains(criteria.name) || uppercaseCustomList.contains(criteria.dialCode)).toList(); + final uppercaseCustomList = + countryFilter!.map((criteria) => criteria.toUpperCase()).toList(); + elements = elements + .where((criteria) => + uppercaseCustomList.contains(criteria.code) || + uppercaseCustomList.contains(criteria.name) || + uppercaseCustomList.contains(criteria.dialCode)) + .toList(); } return CountryCodePickerState(elements, pickerStyle); @@ -197,7 +207,7 @@ class CountryCodePickerState extends State { internalWidget = InkWell( onTap: pickerStyle == PickerStyle.dialog ? showCountryCodePickerDialog - : showCountryCodePickerBottomSheet + : showCountryCodePickerBottomSheet, child: widget.builder!(selectedItem), ); } else { @@ -213,14 +223,21 @@ 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 ? const EdgeInsets.only(right: 16.0, left: 8.0) : const EdgeInsets.only(right: 16.0)), + margin: widget.margin ?? + (widget.alignLeft + ? const EdgeInsets.only(right: 16.0, left: 8.0) + : const EdgeInsets.only(right: 16.0)), child: Image.asset( selectedItem!.flagUri!, package: 'country_code_picker', @@ -232,8 +249,11 @@ 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, ), ), @@ -242,7 +262,9 @@ class CountryCodePickerState extends State { flex: widget.alignLeft ? 0 : 1, 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)), + padding: (widget.alignLeft + ? const EdgeInsets.only(right: 16.0, left: 8.0) + : const EdgeInsets.only(right: 16.0)), child: Icon( Icons.arrow_drop_down, color: Colors.grey, @@ -273,9 +295,11 @@ 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]; @@ -291,9 +315,11 @@ 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]; @@ -301,14 +327,17 @@ class CountryCodePickerState extends State { favoriteElements = elements .where((item) => - widget.favorite.firstWhereOrNull((criteria) => item.code!.toUpperCase() == criteria.toUpperCase() || item.dialCode == criteria || item.name!.toUpperCase() == criteria.toUpperCase()) != + widget.favorite.firstWhereOrNull((criteria) => + item.code!.toUpperCase() == criteria.toUpperCase() || + item.dialCode == criteria || + item.name!.toUpperCase() == criteria.toUpperCase()) != null) .toList(); } void showCountryCodePickerDialog() async { final item = await showDialog( - barrierColor: widget.barrierColor ?? Colors.grey.withOpacity(0.5), + barrierColor: widget.barrierColor ?? Colors.grey.withAlpha(128), context: context, builder: (context) => Center( child: Dialog( diff --git a/lib/src/bottom_sheet.dart b/lib/src/bottom_sheet.dart index 0f32f27..dcb143c 100644 --- a/lib/src/bottom_sheet.dart +++ b/lib/src/bottom_sheet.dart @@ -73,7 +73,8 @@ class _SelectionBottomSheetState extends State { borderRadius: const BorderRadius.all(Radius.circular(8.0)), boxShadow: [ BoxShadow( - color: widget.barrierColor ?? Colors.grey.withOpacity(1), + color: widget.barrierColor ?? Colors.grey + ..withAlpha(255), spreadRadius: 5, blurRadius: 7, offset: const Offset(0, 3), // changes position of shadow diff --git a/lib/src/selection_dialog.dart b/lib/src/selection_dialog.dart index 58b1f97..46cc466 100644 --- a/lib/src/selection_dialog.dart +++ b/lib/src/selection_dialog.dart @@ -88,7 +88,7 @@ class _SelectionDialogState extends State { borderRadius: const BorderRadius.all(Radius.circular(8.0)), boxShadow: [ BoxShadow( - color: widget.barrierColor ?? Colors.grey.withOpacity(1), + color: widget.barrierColor ?? Colors.grey.withAlpha(255), spreadRadius: 5, blurRadius: 7, offset: const Offset(0, 3), // changes position of shadow diff --git a/pubspec.yaml b/pubspec.yaml index c7fc8d8..a654d70 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,12 @@ 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: 3.1.0 +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 homepage: https://github.com/chandrabezzo/CountryCodePicker repository: https://github.com/chandrabezzo/CountryCodePicker issue_tracker: https://github.com/imtoori/CountryCodePicker/issues environment: - sdk: '>=2.17.0 <4.0.0' + sdk: ">=2.17.0 <4.0.0" dependencies: flutter: @@ -87,6 +87,6 @@ flutter: - packages/country_code_picker/src/i18n/uk.json - packages/country_code_picker/src/i18n/uz.json - packages/country_code_picker/src/i18n/zh.json - + dev_dependencies: flutter_lints: ^2.0.1