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

Add anonymous number (+888) #452

Open
wants to merge 9 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
Binary file added assets/flags/anmn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions lib/src/models/country_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,38 @@ class Countries {
static List<Map<String, dynamic>> get countryList => _countryList;

static List<Map<String, dynamic>> _countryList = [
{
"num_code": "888",
"alpha_2_code": "ANMN",
"alpha_3_code": "ANM",
"en_short_name": "Anonymus Number",
"nationality": "Anonymus",
"dial_code": "+888",
"nameTranslations": {
"sk": "Anonymus",
"se": "Anonymus",
"pl": "Anonymus",
"no": "Anonymus",
"ja": "アノニマス",
"it": "Anonymus",
"zh": "匿名",
"nl": "Anonymus",
"de": "Anonymus",
"fr": "Anonymus",
"es": "Anonymus",
"en": "Anonymus",
"pt_BR": "Anonymus",
"sr-Cyrl": "Анонимус",
"sr-Latn": "Anonymus",
"zh_TW": "匿名",
"tr": "Anonymus",
"ro": "Anonymus",
"ar": "مجهول",
"fa": "ناشناس",
"yue": "匿名",
"el": "Ανώνυμος"
}
},
{
"num_code": "4",
"alpha_2_code": "AF",
Expand Down
131 changes: 70 additions & 61 deletions lib/src/widgets/countries_search_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CountrySearchListWidget extends StatefulWidget {
final bool autoFocus;
final bool? showFlags;
final bool? useEmoji;
final Color? backgroundColor;

CountrySearchListWidget(
this.countries,
Expand All @@ -21,6 +22,7 @@ class CountrySearchListWidget extends StatefulWidget {
this.showFlags,
this.useEmoji,
this.autoFocus = false,
this.backgroundColor = Colors.white,
});

@override
Expand Down Expand Up @@ -57,69 +59,75 @@ class _CountrySearchListWidgetState extends State<CountrySearchListWidget> {

@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
child: TextFormField(
key: Key(TestHelper.CountrySearchInputKeyValue),
decoration: getSearchBoxDecoration(),
controller: _searchController,
autofocus: widget.autoFocus,
onChanged: (value) {
final String value = _searchController.text.trim();
return setState(
() => filteredCountries = Utils.filterCountries(
countries: widget.countries,
locale: widget.locale,
value: value,
),
);
},
return Container(
color: widget.backgroundColor,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
child: TextFormField(
key: Key(TestHelper.CountrySearchInputKeyValue),
decoration: getSearchBoxDecoration(),
controller: _searchController,
autofocus: widget.autoFocus,
onChanged: (value) {
final String value = _searchController.text.trim();
return setState(
() => filteredCountries = Utils.filterCountries(
countries: widget.countries,
locale: widget.locale,
value: value,
),
);
},
),
),
),
Flexible(
child: ListView.builder(
controller: widget.scrollController,
shrinkWrap: true,
itemCount: filteredCountries.length,
itemBuilder: (BuildContext context, int index) {
Country country = filteredCountries[index];

return DirectionalCountryListTile(
country: country,
locale: widget.locale,
showFlags: widget.showFlags!,
useEmoji: widget.useEmoji!,
);
// return ListTile(
// key: Key(TestHelper.countryItemKeyValue(country.alpha2Code)),
// leading: widget.showFlags!
// ? _Flag(country: country, useEmoji: widget.useEmoji)
// : null,
// title: Align(
// alignment: AlignmentDirectional.centerStart,
// child: Text(
// '${Utils.getCountryName(country, widget.locale)}',
// textDirection: Directionality.of(context),
// textAlign: TextAlign.start,
// ),
// ),
// subtitle: Align(
// alignment: AlignmentDirectional.centerStart,
// child: Text(
// '${country.dialCode ?? ''}',
// textDirection: TextDirection.ltr,
// textAlign: TextAlign.start,
// ),
// ),
// onTap: () => Navigator.of(context).pop(country),
// );
},
Flexible(
child: Container(
color: widget.backgroundColor,
child: ListView.builder(
controller: widget.scrollController,
shrinkWrap: true,
itemCount: filteredCountries.length,
itemBuilder: (BuildContext context, int index) {
Country country = filteredCountries[index];

return DirectionalCountryListTile(
country: country,
locale: widget.locale,
showFlags: widget.showFlags!,
useEmoji: widget.useEmoji!,
);
// return ListTile(
// key: Key(TestHelper.countryItemKeyValue(country.alpha2Code)),
// leading: widget.showFlags!
// ? _Flag(country: country, useEmoji: widget.useEmoji)
// : null,
// title: Align(
// alignment: AlignmentDirectional.centerStart,
// child: Text(
// '${Utils.getCountryName(country, widget.locale)}',
// textDirection: Directionality.of(context),
// textAlign: TextAlign.start,
// ),
// ),
// subtitle: Align(
// alignment: AlignmentDirectional.centerStart,
// child: Text(
// '${country.dialCode ?? ''}',
// textDirection: TextDirection.ltr,
// textAlign: TextAlign.start,
// ),
// ),
// onTap: () => Navigator.of(context).pop(country),
// );
},
),
),
),
),
],
],
),
);
}

Expand Down Expand Up @@ -188,6 +196,7 @@ class _Flag extends StatelessWidget {
)
: country?.flagUri != null
? CircleAvatar(
backgroundColor: Colors.white,
backgroundImage: AssetImage(
country!.flagUri,
package: 'intl_phone_number_input',
Expand Down
25 changes: 24 additions & 1 deletion lib/src/widgets/input_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class InternationalPhoneNumberInput extends StatefulWidget {

final List<String>? countries;

final Color? searchListBackgroundColor;

InternationalPhoneNumberInput(
{Key? key,
this.selectorConfig = const SelectorConfig(),
Expand Down Expand Up @@ -124,7 +126,8 @@ class InternationalPhoneNumberInput extends StatefulWidget {
this.focusNode,
this.cursorColor,
this.autofillHints,
this.countries})
this.countries,
this.searchListBackgroundColor = Colors.white,})
: super(key: key);

@override
Expand Down Expand Up @@ -228,6 +231,22 @@ class _InputWidgetState extends State<InternationalPhoneNumberInput> {
String parsedPhoneNumberString =
controller!.text.replaceAll(RegExp(r'[^\d+]'), '');

// Skip checking if the country code is +888
if (this.country?.dialCode == '+888' && parsedPhoneNumberString.length >= 5) {
if (widget.onInputChanged != null) {
widget.onInputChanged!(PhoneNumber(
phoneNumber: parsedPhoneNumberString,
isoCode: this.country?.alpha2Code,
dialCode: this.country?.dialCode));
}

if (widget.onInputValidated != null) {
widget.onInputValidated!(true);
}
this.isNotValid = false;
return;
}

getParsedPhoneNumber(parsedPhoneNumberString, this.country?.alpha2Code)
.then((phoneNumber) {
if (phoneNumber == null) {
Expand Down Expand Up @@ -318,6 +337,10 @@ class _InputWidgetState extends State<InternationalPhoneNumberInput> {
///
/// Also updates [selectorButtonBottomPadding]
String? validator(String? value) {
if (country?.dialCode == '+888' && (value?.length ?? 0) >= 5) {
return null;
}

bool isValid =
this.isNotValid && (value!.isNotEmpty || widget.ignoreBlank == false);
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/widgets/selector_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SelectorButton extends StatelessWidget {
final bool isScrollControlled;

final ValueChanged<Country?> onCountryChanged;
final Color? searchListBackgroundColor;

const SelectorButton({
Key? key,
Expand All @@ -32,6 +33,7 @@ class SelectorButton extends StatelessWidget {
required this.onCountryChanged,
required this.isEnabled,
required this.isScrollControlled,
this.searchListBackgroundColor = Colors.white,
}) : super(key: key);

@override
Expand Down Expand Up @@ -134,6 +136,7 @@ class SelectorButton extends StatelessWidget {
showFlags: selectorConfig.showFlags,
useEmoji: selectorConfig.useEmoji,
autoFocus: autoFocusSearchField,
backgroundColor: searchListBackgroundColor,
),
),
),
Expand Down Expand Up @@ -183,6 +186,7 @@ class SelectorButton extends StatelessWidget {
showFlags: selectorConfig.showFlags,
useEmoji: selectorConfig.useEmoji,
autoFocus: autoFocusSearchField,
backgroundColor: searchListBackgroundColor,
),
),
);
Expand Down