Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the libphonenumber_plugin dep to fix some bugs: #374

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class _MyHomePageState extends State<MyHomePage> {

void getPhoneNumber(String phoneNumber) async {
PhoneNumber number =
await PhoneNumber.getRegionInfoFromPhoneNumber(phoneNumber, 'US');
await PhoneNumber.getRegionInfoFromPhoneNumber(phoneNumber);

setState(() {
this.number = number;
Expand Down
8 changes: 4 additions & 4 deletions lib/src/utils/selector_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
3 changes: 1 addition & 2 deletions lib/src/widgets/input_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ class _InputWidgetState extends State<InternationalPhoneNumberInput> {
);

if (widget.selectorConfig.setSelectorButtonAsPrefixIcon) {
return value.copyWith(
prefixIcon: SelectorButton(
return value.copyWith(prefixIcon: SelectorButton(
country: country,
countries: countries,
onCountryChanged: onCountryChanged,
Expand Down
3 changes: 0 additions & 3 deletions lib/src/widgets/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -19,7 +18,6 @@ class Item extends StatelessWidget {
this.useEmoji,
this.textStyle,
this.withCountryNames = false,
this.leadingPadding = 12,
this.trailingSpace = true,
}) : super(key: key);

Expand All @@ -34,7 +32,6 @@ class Item extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(width: leadingPadding),
_Flag(
country: country,
showFlag: showFlag,
Expand Down
111 changes: 56 additions & 55 deletions lib/src/widgets/selector_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Country>(
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<Country>(
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`
Expand Down