diff --git a/CHANGELOG.md b/CHANGELOG.md index 85633b7..88426a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - use modal_bottom_sheet 2.0.0 - nullable integration - switch to dialog on desktop app support +- added flagDecoration ## 1.7.0 diff --git a/lib/country_code.dart b/lib/country_code.dart index 9267318..3d1a6b4 100644 --- a/lib/country_code.dart +++ b/lib/country_code.dart @@ -69,6 +69,10 @@ class CountryCode { String toLongString() => "$dialCode ${toCountryStringOnly()}"; String toCountryStringOnly() { - return '$name'; + return '$_cleanName'; + } + + String? get _cleanName { + return name?.replaceAll(RegExp(r'[[\]]'), '').split(',').first; } } diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 8a71867..6a04445 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -87,7 +87,7 @@ class CountryCodePicker extends StatefulWidget { this.initialSelection, this.favorite = const [], this.textStyle, - this.padding = const EdgeInsets.all(0.0), + this.padding = const EdgeInsets.all(8.0), this.showCountryOnly = false, this.searchDecoration = const InputDecoration(), this.searchStyle, @@ -160,59 +160,63 @@ class CountryCodePickerState extends State { child: widget.builder!(selectedItem), ); else { - _widget = FlatButton( - padding: widget.padding, + _widget = TextButton( onPressed: widget.enabled ? showCountryCodePickerDialog : null, - child: Flex( - direction: Axis.horizontal, - mainAxisSize: MainAxisSize.min, - children: [ - 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, - decoration: widget.flagDecoration, - 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', - width: widget.flagWidth, - ), - ), - ), - if (!widget.hideMainText) - Flexible( - fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, - child: Text( - widget.showOnlyCountryWhenClosed - ? selectedItem!.toCountryStringOnly() - : selectedItem.toString(), - style: widget.textStyle ?? Theme.of(context).textTheme.button, - overflow: widget.textOverflow, - ), - ), - if (widget.showDropDownButton) - Flexible( - flex: widget.alignLeft ? 0 : 1, - fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, - child: Padding( - padding: widget.alignLeft + child: Padding( + padding: widget.padding, + child: Flex( + direction: Axis.horizontal, + mainAxisSize: MainAxisSize.min, + children: [ + 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, + decoration: widget.flagDecoration, + margin: 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, - size: widget.flagWidth, - )), - ), - ], + child: Image.asset( + selectedItem!.flagUri!, + package: 'country_code_picker', + width: widget.flagWidth, + ), + ), + ), + if (!widget.hideMainText) + Flexible( + fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, + child: Text( + widget.showOnlyCountryWhenClosed + ? selectedItem!.toCountryStringOnly() + : selectedItem.toString(), + style: + widget.textStyle ?? Theme.of(context).textTheme.button, + overflow: widget.textOverflow, + ), + ), + if (widget.showDropDownButton) + Flexible( + 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), + child: Icon( + Icons.arrow_drop_down, + color: Colors.grey, + size: widget.flagWidth, + )), + ), + ], + ), ), ); }