diff --git a/lib/src/utils/selector_config.dart b/lib/src/utils/selector_config.dart index 7db965673c..b643dcb05c 100644 --- a/lib/src/utils/selector_config.dart +++ b/lib/src/utils/selector_config.dart @@ -33,6 +33,9 @@ class SelectorConfig { /// Add white space for short dial code final bool trailingSpace; + /// The padding around the selector. + final EdgeInsets? padding; + const SelectorConfig({ this.selectorType = PhoneInputSelectorType.DROPDOWN, this.showFlags = true, @@ -41,5 +44,6 @@ class SelectorConfig { this.setSelectorButtonAsPrefixIcon = false, this.leadingPadding, this.trailingSpace = true, + 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/selector_button.dart b/lib/src/widgets/selector_button.dart index 31cc77b1c8..8a6e2114e1 100644 --- a/lib/src/widgets/selector_button.dart +++ b/lib/src/widgets/selector_button.dart @@ -36,65 +36,69 @@ 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, + leadingPadding: selectorConfig.leadingPadding, + 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, + 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); + } - 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, + leadingPadding: selectorConfig.leadingPadding, + trailingSpace: selectorConfig.trailingSpace, + textStyle: selectorTextStyle, ), - ); + ), + ); + if (selectorConfig.padding != null) { + button = Padding(padding: selectorConfig.padding!, child: button); + } + return button; } /// Converts the list [countries] to `DropdownMenuItem`