From 0067f9fb460099469ec176dd0cd2d100c87331d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastien=20Gruhier?= Date: Mon, 10 Apr 2023 14:58:32 +0200 Subject: [PATCH 1/2] remove padding, should be managed by ThemeData --- lib/src/widgets/selector_button.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/widgets/selector_button.dart b/lib/src/widgets/selector_button.dart index 31cc77b1c8..a11ad55851 100644 --- a/lib/src/widgets/selector_button.dart +++ b/lib/src/widgets/selector_button.dart @@ -64,7 +64,6 @@ class SelectorButton extends StatelessWidget { ) : MaterialButton( key: Key(TestHelper.DropdownButtonKeyValue), - padding: EdgeInsets.zero, minWidth: 0, onPressed: countries.isNotEmpty && countries.length > 1 && isEnabled ? () async { From 1a0420af69d1bc092d88e4bb1bc9cab908edcfbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastien=20Gruhier?= Date: Fri, 14 Jul 2023 16:26:28 +0200 Subject: [PATCH 2/2] add buttonDecoration --- lib/src/widgets/input_widget.dart | 71 ++++++++++------------------ lib/src/widgets/selector_button.dart | 38 ++++++++------- 2 files changed, 45 insertions(+), 64 deletions(-) diff --git a/lib/src/widgets/input_widget.dart b/lib/src/widgets/input_widget.dart index 94972bad18..cf8c2a475e 100644 --- a/lib/src/widgets/input_widget.dart +++ b/lib/src/widgets/input_widget.dart @@ -75,6 +75,7 @@ class InternationalPhoneNumberInput extends StatefulWidget { final TextStyle? selectorTextStyle; final InputBorder? inputBorder; final InputDecoration? inputDecoration; + final InputDecoration? buttonDecoration; final InputDecoration? searchBoxDecoration; final Color? cursorColor; final TextAlign textAlign; @@ -118,6 +119,7 @@ class InternationalPhoneNumberInput extends StatefulWidget { this.inputBorder, this.inputDecoration, this.searchBoxDecoration, + this.buttonDecoration, this.textAlign = TextAlign.start, this.textAlignVertical = TextAlignVertical.center, this.scrollPadding = const EdgeInsets.all(20.0), @@ -179,14 +181,10 @@ class _InputWidgetState extends State { if (widget.initialValue!.phoneNumber != null && widget.initialValue!.phoneNumber!.isNotEmpty && (await PhoneNumberUtil.isValidNumber( - phoneNumber: widget.initialValue!.phoneNumber!, - isoCode: widget.initialValue!.isoCode!))!) { - String phoneNumber = - await PhoneNumber.getParsableNumber(widget.initialValue!); + phoneNumber: widget.initialValue!.phoneNumber!, isoCode: widget.initialValue!.isoCode!))!) { + String phoneNumber = await PhoneNumber.getParsableNumber(widget.initialValue!); - controller!.text = widget.formatInput - ? phoneNumber - : phoneNumber.replaceAll(RegExp(r'[^\d+]'), ''); + controller!.text = widget.formatInput ? phoneNumber : phoneNumber.replaceAll(RegExp(r'[^\d+]'), ''); phoneNumberControllerListener(); } @@ -196,8 +194,7 @@ class _InputWidgetState extends State { /// loads countries from [Countries.countryList] and selected Country void loadCountries({Country? previouslySelectedCountry}) { if (this.mounted) { - List countries = - CountryProvider.getCountriesData(countries: widget.countries); + List countries = CountryProvider.getCountriesData(countries: widget.countries); Country country = previouslySelectedCountry ?? Utils.getInitialSelectedCountry( @@ -208,8 +205,7 @@ class _InputWidgetState extends State { // Remove potential duplicates countries = countries.toSet().toList(); - final CountryComparator? countryComparator = - widget.selectorConfig.countryComparator; + final CountryComparator? countryComparator = widget.selectorConfig.countryComparator; if (countryComparator != null) { countries.sort(countryComparator); } @@ -225,20 +221,15 @@ class _InputWidgetState extends State { /// the `ValueCallback` [widget.onInputValidated] void phoneNumberControllerListener() { if (this.mounted) { - String parsedPhoneNumberString = - controller!.text.replaceAll(RegExp(r'[^\d+]'), ''); + String parsedPhoneNumberString = controller!.text.replaceAll(RegExp(r'[^\d+]'), ''); - getParsedPhoneNumber(parsedPhoneNumberString, this.country?.alpha2Code) - .then((phoneNumber) { + getParsedPhoneNumber(parsedPhoneNumberString, this.country?.alpha2Code).then((phoneNumber) { if (phoneNumber == null) { - String phoneNumber = - '${this.country?.dialCode}$parsedPhoneNumberString'; + String phoneNumber = '${this.country?.dialCode}$parsedPhoneNumberString'; if (widget.onInputChanged != null) { widget.onInputChanged!(PhoneNumber( - phoneNumber: phoneNumber, - isoCode: this.country?.alpha2Code, - dialCode: this.country?.dialCode)); + phoneNumber: phoneNumber, isoCode: this.country?.alpha2Code, dialCode: this.country?.dialCode)); } if (widget.onInputValidated != null) { @@ -248,9 +239,7 @@ class _InputWidgetState extends State { } else { if (widget.onInputChanged != null) { widget.onInputChanged!(PhoneNumber( - phoneNumber: phoneNumber, - isoCode: this.country?.alpha2Code, - dialCode: this.country?.dialCode)); + phoneNumber: phoneNumber, isoCode: this.country?.alpha2Code, dialCode: this.country?.dialCode)); } if (widget.onInputValidated != null) { @@ -264,16 +253,13 @@ class _InputWidgetState extends State { /// Returns a formatted String of [phoneNumber] with [isoCode], returns `null` /// if [phoneNumber] is not valid or if an [Exception] is caught. - Future getParsedPhoneNumber( - String phoneNumber, String? isoCode) async { + Future getParsedPhoneNumber(String phoneNumber, String? isoCode) async { if (phoneNumber.isNotEmpty && isoCode != null) { try { - bool? isValidPhoneNumber = await PhoneNumberUtil.isValidNumber( - phoneNumber: phoneNumber, isoCode: isoCode); + bool? isValidPhoneNumber = await PhoneNumberUtil.isValidNumber(phoneNumber: phoneNumber, isoCode: isoCode); if (isValidPhoneNumber!) { - return await PhoneNumberUtil.normalizePhoneNumber( - phoneNumber: phoneNumber, isoCode: isoCode); + return await PhoneNumberUtil.normalizePhoneNumber(phoneNumber: phoneNumber, isoCode: isoCode); } } on Exception { return null; @@ -318,13 +304,11 @@ class _InputWidgetState extends State { /// /// Also updates [selectorButtonBottomPadding] String? validator(String? value) { - bool isValid = - this.isNotValid && (value!.isNotEmpty || widget.ignoreBlank == false); + bool isValid = this.isNotValid && (value!.isNotEmpty || widget.ignoreBlank == false); WidgetsBinding.instance.addPostFrameCallback((timeStamp) { if (isValid && widget.errorMessage != null) { setState(() { - this.selectorButtonBottomPadding = - widget.selectorButtonOnErrorPadding; + this.selectorButtonBottomPadding = widget.selectorButtonOnErrorPadding; }); } else { setState(() { @@ -346,17 +330,12 @@ class _InputWidgetState extends State { void _phoneNumberSaved() { if (this.mounted) { - String parsedPhoneNumberString = - controller!.text.replaceAll(RegExp(r'[^\d+]'), ''); + String parsedPhoneNumberString = controller!.text.replaceAll(RegExp(r'[^\d+]'), ''); - String phoneNumber = - '${this.country?.dialCode ?? ''}' + parsedPhoneNumberString; + String phoneNumber = '${this.country?.dialCode ?? ''}' + parsedPhoneNumberString; widget.onSaved?.call( - PhoneNumber( - phoneNumber: phoneNumber, - isoCode: this.country?.alpha2Code, - dialCode: this.country?.dialCode), + PhoneNumber(phoneNumber: phoneNumber, isoCode: this.country?.alpha2Code, dialCode: this.country?.dialCode), ); } } @@ -370,20 +349,17 @@ class _InputWidgetState extends State { String? get locale { if (widget.locale == null) return null; - if (widget.locale!.toLowerCase() == 'nb' || - widget.locale!.toLowerCase() == 'nn') { + if (widget.locale!.toLowerCase() == 'nb' || widget.locale!.toLowerCase() == 'nn') { return 'no'; } return widget.locale; } } -class _InputWidgetView - extends WidgetView { +class _InputWidgetView extends WidgetView { final _InputWidgetState state; - _InputWidgetView({Key? key, required this.state}) - : super(key: key, state: state); + _InputWidgetView({Key? key, required this.state}) : super(key: key, state: state); @override Widget build(BuildContext context) { @@ -406,6 +382,7 @@ class _InputWidgetView selectorConfig: widget.selectorConfig, selectorTextStyle: widget.selectorTextStyle, searchBoxDecoration: widget.searchBoxDecoration, + buttonColor: widget.buttonDecoration?.fillColor, locale: state.locale, isEnabled: widget.isEnabled, autoFocusSearchField: widget.autoFocusSearch, diff --git a/lib/src/widgets/selector_button.dart b/lib/src/widgets/selector_button.dart index a11ad55851..b61fbced75 100644 --- a/lib/src/widgets/selector_button.dart +++ b/lib/src/widgets/selector_button.dart @@ -17,6 +17,7 @@ class SelectorButton extends StatelessWidget { final String? locale; final bool isEnabled; final bool isScrollControlled; + final Color? buttonColor; final ValueChanged onCountryChanged; @@ -32,6 +33,7 @@ class SelectorButton extends StatelessWidget { required this.onCountryChanged, required this.isEnabled, required this.isScrollControlled, + this.buttonColor, }) : super(key: key); @override @@ -65,16 +67,19 @@ class SelectorButton extends StatelessWidget { : MaterialButton( key: Key(TestHelper.DropdownButtonKeyValue), minWidth: 0, + height: 0, + color: buttonColor, // background + elevation: 0, + hoverElevation: 0, + focusElevation: 0, + highlightElevation: 0, onPressed: countries.isNotEmpty && countries.length > 1 && isEnabled ? () async { Country? selected; - if (selectorConfig.selectorType == - PhoneInputSelectorType.BOTTOM_SHEET) { - selected = await showCountrySelectorBottomSheet( - context, countries); + if (selectorConfig.selectorType == PhoneInputSelectorType.BOTTOM_SHEET) { + selected = await showCountrySelectorBottomSheet(context, countries); } else { - selected = - await showCountrySelectorDialog(context, countries); + selected = await showCountrySelectorDialog(context, countries); } if (selected != null) { @@ -83,7 +88,7 @@ class SelectorButton extends StatelessWidget { } : null, child: Padding( - padding: const EdgeInsets.only(right: 8.0), + padding: const EdgeInsets.only(right: 8.0, top: 1, bottom: 1), child: Item( country: country, showFlag: selectorConfig.showFlags, @@ -97,8 +102,7 @@ class SelectorButton extends StatelessWidget { } /// Converts the list [countries] to `DropdownMenuItem` - List> mapCountryToDropdownItem( - List countries) { + List> mapCountryToDropdownItem(List countries) { return countries.map((country) { return DropdownMenuItem( value: country, @@ -116,8 +120,7 @@ class SelectorButton extends StatelessWidget { } /// shows a Dialog with list [countries] if the [PhoneInputSelectorType.DIALOG] is selected - Future showCountrySelectorDialog( - BuildContext inheritedContext, List countries) { + Future showCountrySelectorDialog(BuildContext inheritedContext, List countries) { return showDialog( context: inheritedContext, barrierDismissible: true, @@ -141,25 +144,26 @@ class SelectorButton extends StatelessWidget { } /// shows a Dialog with list [countries] if the [PhoneInputSelectorType.BOTTOM_SHEET] is selected - Future showCountrySelectorBottomSheet( - BuildContext inheritedContext, List countries) { + Future showCountrySelectorBottomSheet(BuildContext inheritedContext, List countries) { return showModalBottomSheet( context: inheritedContext, clipBehavior: Clip.hardEdge, isScrollControlled: isScrollControlled, + useSafeArea: true, backgroundColor: Colors.transparent, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(12), topRight: Radius.circular(12))), + borderRadius: BorderRadius.only(topLeft: Radius.circular(12), topRight: Radius.circular(12))), builder: (BuildContext context) { return Stack(children: [ GestureDetector( onTap: () => Navigator.pop(context), ), Padding( - padding: EdgeInsets.only( - bottom: MediaQuery.of(context).viewInsets.bottom), + padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), child: DraggableScrollableSheet( + // initialChildSize: 0.5, + // minChildSize: 0.25, + // maxChildSize: 0.7, builder: (BuildContext context, ScrollController controller) { return Directionality( textDirection: Directionality.of(inheritedContext),