From 99ba319ca682027ff2730628e31cd1517ee48e7c Mon Sep 17 00:00:00 2001 From: Sergey Elokhin Date: Sat, 4 Mar 2023 18:04:25 +0300 Subject: [PATCH 1/2] Update the libphonenumber_plugin dep to fix some bugs: - extra digital country code in the formatted number, - getRegionInfoFromPhoneNumber crashes on iOS platform. --- example/lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 830a61baec..b04bbbbd14 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -93,7 +93,7 @@ class _MyHomePageState extends State { void getPhoneNumber(String phoneNumber) async { PhoneNumber number = - await PhoneNumber.getRegionInfoFromPhoneNumber(phoneNumber, 'US'); + await PhoneNumber.getRegionInfoFromPhoneNumber(phoneNumber); setState(() { this.number = number; From 02d1c958f1b8420c1c415c7641bb9a6322bccea8 Mon Sep 17 00:00:00 2001 From: Sergey Elokhin Date: Sat, 4 Mar 2023 23:06:06 +0300 Subject: [PATCH 2/2] Support padding around the selector button. --- lib/src/utils/selector_config.dart | 8 +- lib/src/widgets/input_widget.dart | 3 +- lib/src/widgets/item.dart | 3 - lib/src/widgets/selector_button.dart | 111 ++++++++++++++------------- 4 files changed, 61 insertions(+), 64 deletions(-) diff --git a/lib/src/utils/selector_config.dart b/lib/src/utils/selector_config.dart index 75c7f4c1e4..eb3c44bb21 100644 --- a/lib/src/utils/selector_config.dart +++ b/lib/src/utils/selector_config.dart @@ -27,23 +27,23 @@ class SelectorConfig { /// [setSelectorButtonAsPrefixIcon], this sets/places the selector button inside the [TextField] as a prefixIcon. final bool setSelectorButtonAsPrefixIcon; - /// Space before the flag icon - final double? leadingPadding; - /// Add white space for short dial code final bool trailingSpace; /// Use safe area for selectorType=BOTTOM_SHEET final bool useBottomSheetSafeArea; + /// The padding around the selector. + final EdgeInsets? padding; + const SelectorConfig({ this.selectorType = PhoneInputSelectorType.DROPDOWN, this.showFlags = true, this.useEmoji = false, this.countryComparator, this.setSelectorButtonAsPrefixIcon = false, - this.leadingPadding, this.trailingSpace = true, this.useBottomSheetSafeArea = false, + this.padding, }); } diff --git a/lib/src/widgets/input_widget.dart b/lib/src/widgets/input_widget.dart index 94972bad18..026cf9899d 100644 --- a/lib/src/widgets/input_widget.dart +++ b/lib/src/widgets/input_widget.dart @@ -291,8 +291,7 @@ class _InputWidgetState extends State { ); if (widget.selectorConfig.setSelectorButtonAsPrefixIcon) { - return value.copyWith( - prefixIcon: SelectorButton( + return value.copyWith(prefixIcon: SelectorButton( country: country, countries: countries, onCountryChanged: onCountryChanged, diff --git a/lib/src/widgets/item.dart b/lib/src/widgets/item.dart index c0b2ab9f51..8e2cddd284 100644 --- a/lib/src/widgets/item.dart +++ b/lib/src/widgets/item.dart @@ -9,7 +9,6 @@ class Item extends StatelessWidget { final bool? useEmoji; final TextStyle? textStyle; final bool withCountryNames; - final double? leadingPadding; final bool trailingSpace; const Item({ @@ -19,7 +18,6 @@ class Item extends StatelessWidget { this.useEmoji, this.textStyle, this.withCountryNames = false, - this.leadingPadding = 12, this.trailingSpace = true, }) : super(key: key); @@ -34,7 +32,6 @@ class Item extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ - SizedBox(width: leadingPadding), _Flag( country: country, showFlag: showFlag, diff --git a/lib/src/widgets/selector_button.dart b/lib/src/widgets/selector_button.dart index 70672e89cc..19d22b276a 100644 --- a/lib/src/widgets/selector_button.dart +++ b/lib/src/widgets/selector_button.dart @@ -36,65 +36,66 @@ class SelectorButton extends StatelessWidget { @override Widget build(BuildContext context) { - return selectorConfig.selectorType == PhoneInputSelectorType.DROPDOWN - ? countries.isNotEmpty && countries.length > 1 - ? DropdownButtonHideUnderline( - child: DropdownButton( - key: Key(TestHelper.DropdownButtonKeyValue), - hint: Item( - country: country, - showFlag: selectorConfig.showFlags, - useEmoji: selectorConfig.useEmoji, - leadingPadding: selectorConfig.leadingPadding, - trailingSpace: selectorConfig.trailingSpace, - textStyle: selectorTextStyle, - ), - value: country, - items: mapCountryToDropdownItem(countries), - onChanged: isEnabled ? onCountryChanged : null, + Widget button = selectorConfig.selectorType == PhoneInputSelectorType.DROPDOWN + ? countries.isNotEmpty && countries.length > 1 + ? DropdownButtonHideUnderline( + child: DropdownButton( + key: Key(TestHelper.DropdownButtonKeyValue), + hint: Item( + country: country, + showFlag: selectorConfig.showFlags, + useEmoji: selectorConfig.useEmoji, + trailingSpace: selectorConfig.trailingSpace, + textStyle: selectorTextStyle, ), - ) - : Item( - country: country, - showFlag: selectorConfig.showFlags, - useEmoji: selectorConfig.useEmoji, - leadingPadding: selectorConfig.leadingPadding, - trailingSpace: selectorConfig.trailingSpace, - textStyle: selectorTextStyle, - ) - : MaterialButton( - key: Key(TestHelper.DropdownButtonKeyValue), - padding: EdgeInsets.zero, - minWidth: 0, - onPressed: countries.isNotEmpty && countries.length > 1 && isEnabled - ? () async { - Country? selected; - if (selectorConfig.selectorType == - PhoneInputSelectorType.BOTTOM_SHEET) { - selected = await showCountrySelectorBottomSheet( - context, countries); - } else { - selected = - await showCountrySelectorDialog(context, countries); - } + value: country, + items: mapCountryToDropdownItem(countries), + onChanged: isEnabled ? onCountryChanged : null, + ), + ) + : Item( + country: country, + showFlag: selectorConfig.showFlags, + useEmoji: selectorConfig.useEmoji, + trailingSpace: selectorConfig.trailingSpace, + textStyle: selectorTextStyle, + ) + : MaterialButton( + key: Key(TestHelper.DropdownButtonKeyValue), + padding: EdgeInsets.zero, + minWidth: 0, + onPressed: countries.isNotEmpty && countries.length > 1 && isEnabled + ? () async { + Country? selected; + if (selectorConfig.selectorType == + PhoneInputSelectorType.BOTTOM_SHEET) { + selected = await showCountrySelectorBottomSheet( + context, countries); + } else { + selected = + await showCountrySelectorDialog(context, countries); + } - if (selected != null) { - onCountryChanged(selected); - } + if (selected != null) { + onCountryChanged(selected); } - : null, - child: Padding( - padding: const EdgeInsets.only(right: 8.0), - child: Item( - country: country, - showFlag: selectorConfig.showFlags, - useEmoji: selectorConfig.useEmoji, - leadingPadding: selectorConfig.leadingPadding, - trailingSpace: selectorConfig.trailingSpace, - textStyle: selectorTextStyle, - ), + } + : null, + child: Padding( + padding: const EdgeInsets.only(right: 8.0), + child: Item( + country: country, + showFlag: selectorConfig.showFlags, + useEmoji: selectorConfig.useEmoji, + trailingSpace: selectorConfig.trailingSpace, + textStyle: selectorTextStyle, ), - ); + ), + ); + if (selectorConfig.padding != null) { + button = Padding(padding: selectorConfig.padding!, child: button); + } + return button; } /// Converts the list [countries] to `DropdownMenuItem`