natintosh / intl_phone_number_input Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
when I set: ' selectorType: PhoneInputSelectorType.DIALOG', I got the error massage :
flutter: Another exception was thrown: RenderBox was not laid out: RenderIntrinsicWidth#ef124 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
flutter: Another exception was thrown: RenderBox was not laid out: _RenderInkFeatures#7bd8b relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
flutter: Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#0a2be relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
flutter: Another exception was thrown: RenderBox was not laid out: RenderPhysicalShape#c0116 relayoutBoundary=up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
flutter: Another exception was thrown: 'package:flutter/src/rendering/shifted_box.dart': Failed assertion: line 322 pos 12: 'child.hasSize': is not true.
flutter: Another exception was thrown: RenderBox was not laid out: RenderPhysicalShape#c0116 relayoutBoundary=up2
flutter: Another exception was thrown: Updated layout information required for RenderFlex#2bef2 NEEDS-LAYOUT NEEDS-PAINT to calculate semantics.
what can I do to solve the problem?
How to check the detail of Available Parameters?such as ,i want to set some properties of inputDecoration,but i don't know how to do,because i don't know what properties does 'inputDecoration' have?
While the validation and input work fine (great work!), the country list needs some improvements imo. Scrolling through hundreds of flags until you see your code by chance is not very user friendly.
My suggestions:
some times the phone field has some number which can not remove by backspace. but, doesn't print that value in onChanged method and unfortunately displays on the phone field.
eg, the field has and display some number: 66605
onChanged method print: only country code (coz, I remove the field number by pressing backspace)
When formatInput
is true, the input is formatted according to the selected country (e.g. "1234" becomes "12 34" for Country X and "12-34" for Country Y). The problem is, when the country is changed, the input format is not updated (e.g. when changing Country X to Country Y, "-" should be added).
Great work on being one of the first to finally add a phone input package!
A few issues and requests:
Hi,
Thanks for the package. Any reason why initialCountry2letterCode parameter was removed and the alternative solution to set the initial country code ?
Thanks
I want setting Chinese as the local language ,so I add the code " locale:'fr_FR' " to InternationalPhoneNumberInput(), but it does not work.why? How can I set local language ?
InternationalPhoneNumberInput(
onInputChanged: (PhoneNumber number) {
account = number.parseNumber();
locale:'zh_CN',
ignoreBlank: true,
autoValidate: false,
initialValue: PhoneNumber(isoCode: 'CN'),
textFieldController: widget.controller,
inputBorder: OutlineInputBorder(),
selectorType: PhoneInputSelectorType.BOTTOM_SHEET,
inputDecoration: InputDecoration.collapsed(
border: UnderlineInputBorder(),
hintText: allTranslations.text('phoneNumber'),
),
),
Hey thanks for the package!
I was trying it out but unfortunately there is no "validator" parameter like for a TextFormField and I need it since I'm working with a Stepper and the flutter Bloc logic so I use it that way:
validator: (_) => state.compteStatus == StepStatus.invalid ? 'Entrez une adresse sous la forme "[email protected]".' : null,
Thanks!
When the input is invalid, an error message ("Invalid phone number") will appear. Unfortunately, the textbox+message combo makes the right-side taller and, since the prefix is vertically aligned, the layout looks weird. The prefix vertical alignment should stay the same.
In addition to that, it would be great if there's a flag to hide the error message (can't set it to null, will default to "Invalid phone number"). When this widget is used alone e.g. in a "log in by phone" screen, some apps prefer to show error dialog instead (for consistency with other screens perhaps), and the red-colored textbox outline should already give a clue.
Turn on All Exceptions and there are a few.
I try to type a number and after the first character, I get an index out of range. the offset below is 1 and the length of the string is 1 (first digit).
formatAsYouType(input: textToParse).then(
(String value) {
String parsedText = value.replaceFirst(dialCode, '').trim();
int offset = newValue.selection.baseOffset;
try {
if (separatorChars.hasMatch(parsedText[offset])) {
Second crash. In InputWidget. If you don't set an initialValue, then didUpdateWidget tries to access null oldWidget.initialValue.hash (initialValue is null).
@OverRide
void didUpdateWidget(InternationalPhoneNumberInput oldWidget) {
if (oldWidget.initialValue != widget.initialValue ||
oldWidget.initialValue.hash != widget.initialValue.hash) {
loadCountries(context);
initialiseWidget();
Hi, I have a problem with this widget.
In my widget I have a timer, in fact, the timer is a countdown that will call every 1 sec,
My problem is that by using setState() this widget will be rebuilt, Also using Key doesn't solve my problem.
The example code needs a few changes to compile. Would be great to have a real example project. This is the best phone input on flutter, continue to make it better.
The country code and flag alignment gone if I specific only 1 country to show out at the moment.
InternationalPhoneNumberInput(
onInputChanged: (PhoneNumber number) {
print(number.phoneNumber);
},
isEnabled: true,
autoValidate: true,
formatInput: true,
countries: ['MY'],
),
If there's more than 1 country in array, then it working fine.
I want to edit mobile number which comes with country code but there is no option like controller or no intial value input provided how can i use this input type when i want to edit field. kindly help.
printing the phone number inside onInputChanged is returning the expected number with country code, however passing the number through textFieldController is only returning the number without the country code to the TextEditingController().
The bug
Exception thrown when editing the phone and can't validate.
Package version
0.4.5
Flutter version / Flutter doctor
$ flutter doctor -v
[✓] Flutter (Channel beta, 1.18.0-11.1.pre, on Mac OS X 10.15.5 19F101, locale fr-FR)
• Flutter version 1.18.0-11.1.pre at ...
• Framework revision 2738a1148b (4 weeks ago), 2020-05-13 15:24:36 -0700
• Engine revision ef9215ceb2
• Dart version 2.9.0 (build 2.9.0-8.2.beta)
[✓] ...
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.8.4
[✓] ...
[✓] ...
[✓] VS Code (version 1.46.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.11.0
[✓] ...
• No issues found!
My code
InternationalPhoneNumberInput(
textFieldController: phoneCtrl,
keyboardAction: TextInputAction.next,
countries: ['FR'],
initialValue: PhoneNumber(isoCode: 'FR'),
inputDecoration: InputDecoration(
labelText: 'Numéro de téléphone'
),
errorMessage: 'Numéro de téléphone non valide',
onInputChanged: (PhoneNumber value) {
// code
}, // EDIT
),
Errors
[VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: The method 'call' was called on null.
Receiver: null
Tried calling: call()
#0 _InputWidgetState.phoneNumberControllerListener.<anonymous closure>
package:intl_phone_number_input/…/widgets/input_widget.dart:308
#1 _rootRunUnary (dart:async/zone.dart:1192:38)
#2 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#3 _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#4 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:686:45)
#5 Future._propagateToListeners (dart:async/future_impl.dart:715:32)
#6 Future._completeWithValue (dart:async/future_impl.dart:526:5)
#7 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:36:15)
#8 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:303:13)
#9 _InputWidgetState.getParsedPhoneNumber (package:intl_phone_number_input/src/widgets/input_widget.dart)
<asynchronous suspension>
#10 <…>
Platforms
hintText:
doesn't show up on any platforms... ): and on Web versions, it seems to not validate the phone )))):::::
# sign_up.dart
PhoneNumber phone;
...
SizedBox(height: 20.0,),
InternationalPhoneNumberInput(
onInputChanged: (PhoneNumber input){
setState(() => phone = input);
},
initialCountry2LetterCode: "US",
isEnabled: true,
selectorType: PhoneInputSelectorType.DIALOG,
autoValidate: true,
hintText: 'phone number',
errorMessage: "*invalid phone number",
onInputValidated: (val) => print(val),
formatInput: true,
inputDecoration: InputDecoration(border: UnderlineInputBorder()),
),
...
In the last update I can not choose another country
When a text controller is specified, it is the callers responsibility to dispose of it at the proper time. Do not call dispose() on the supplied controller. Otherwise the following error may occur:
Unhandled Exception: A InputProvider was used after being disposed.
Once you have called dispose() on a InputProvider, it can no longer be used.
This was introduced by the implementation of issue #3
This has never happened before, now it happens after you updated your new pgk version.
`
InternationalPhoneNumberInput(
textFieldController: _phoneController,
onInputChanged: onPhoneNumberChanged,
onInputValidated: onInputValidated,
initialCountry2LetterCode: 'VN',
hintText: '(123) 456-789',
)
════════ Exception caught by foundation library ════════════════════════════════════════════════════
The following NoSuchMethodError was thrown while dispatching notifications for TextEditingController:
The getter 'countryCode' was called on null.
Receiver: null
Tried calling: countryCode
When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 _InternationalPhoneNumberInputState._phoneNumberControllerListener (package:intl_phone_number_input/src/widgets/input_widget.dart:167:57)
#2 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:206:21)
#3 ValueNotifier.value= (package:flutter/src/foundation/change_notifier.dart:273:5)
#4 TextEditingController.text= (package:flutter/src/widgets/editable_text.dart:147:5)
...
The TextEditingController sending notification was: TextEditingController#370a6(TextEditingValue(text: ┤+84333111777├, selection: TextSelection(baseOffset: -1, extentOffset: -1, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1)))
════════════════════════════════════════════════════════════════════════════════════════════════════
`
The code still working normally afterward, I guess you did not check null at the initial invoke?
Besides, there are approximately 300 milliseconds for the flag to visible, maybe we should put a circular progress bar or something for clearer experience?
this code exists in _InputWidget
@override
void initState() {
Future.delayed(Duration.zero, () => _loadCountries(context));
controller = widget.textFieldController ?? TextEditingController();
controller.addListener(_phoneNumberControllerListener);
super.initState();
}
@override
void dispose() {
controller?.dispose();
super.dispose();
}
This is understandable behavior if the controller is null and you make a default one.
But if you pass your own controller, it will dispose it for you.
This means, in my Widget holding several controllers and a fields in a ListView, you have to scroll down. If you scroll down, the ListView disposes the widgets that are NOT in view. So if the phone number input widget is disposed OUTSIDE the screen-view, then the number input widget will dispose of the controller you passed to it.
This causes huge errors. The plugin should ONLY dipose its DEFAULT controller, not the manually passed in one. The user must dispose of that by themselves, just like all of flutter's controller handling.
The following assertion was thrown building _DefaultInheritedProviderScope<InputProvider>(value: Instance of 'InputProvider', listening to value):
A TextEditingController was used after being disposed.
Once you have called dispose() on a TextEditingController, it can no longer be used.
The relevant error-causing widget was:
InternationalPhoneNumberInput
Can you add an option enabled like on TextFormField widget to be able to toggle the enabled state?
I'm using the AbsorbPointer widget to wrap the field to disable user input, but it's a hack.
Also it would be nice if we could disable or change the formatting. For example (XXX) XX XXX is not a proper format for Serbian phone numbers, but (XX) XXX XXX.
Also when the initial value is passed, it gives me:
+381 +381XXXXXXXX
instead of
+381 (XXX)XXXXX
btw, nice plugin :)
Hello,
When i put the component inside a form widget always validate the phone number even if you configure autovalidate = false in the properties.
Thanks!
I'd like to listen to onSubmitted which is invoked by the native keyboard.
Could you please add that listener to the API and pass it to the TextField component you're wrapping? It should be pretty straightforward.
If you could go one step further and make it compatible with flutter's Form it'd be even better, after all, this component is likely to be used as part of a form.
Whenever I tap on the text field to enter the keyboard appears for a moment than automatically go back due to which I am not able to write anything in text field.
I am getting following message in debug console
W/IInputConnectionWrapper(14564): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(14564): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(14564): getTextAfterCursor on inactive InputConnection
Following is my code
InternationalPhoneNumberInput(
onInputChanged: (PhoneNumber input) {
setState(() => phone = input);
},
isEnabled: true,
selectorType: PhoneInputSelectorType.DIALOG,
autoValidate: true,
hintText: 'phone number',
errorMessage: "*invalid phone number",
onInputValidated: (val) => print(val),
formatInput: true,
)
The use case:
If I select Canada as country, I want to limit the number to 12 digits.
+1-XXX-XXX-XXXX
Add key values for input fields (ie: "countrySelector" and "phoneInput"), as well as keys for items in the country code list, so that tests can be written to select country codes and input phone numbers. For example:
await driver.tap(find.byValueKey('countrySelector'));
await driver.tap(find.byValueKey('country_US'));
await driver.tap(find.byValueKey('phoneInput'));
await driver.enterText("5555551234");
Pls add images or gif in readme to show the output of the input field.
It will be better for developers to understand it and quickly use it.
Reference can be taken from here. https://api.flutter.dev/flutter/material/SliverAppBar-class.html
I'm using onInputValidated()
to check whether should we enable the NEXT BUTTON.
...
Stack(
children: <Widget>[
InternationalPhoneNumberInput(
onInputChanged: (PhoneNumber number) {
this.number = number;
},
onInputValidated: (bool value) {
setState(() {
_isValid = value;
});
},
ignoreBlank: false,
autoValidate: false,
initialValue: number,
textFieldController: controller,
...
),
Opacity(
opacity: _isValid ? 1.0 : 0.5,
child: FlatButton( onPressed: () {...}, child: Text('Next') )
),
]
)
...
And will get the error below
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(NumberParseException, The string supplied did not seem to be a phone number., null)
Hi,
Is that possible to use the text field autofocus in the constructor ?
Thanks for the answer
I'm using your package in a single field form with autovalidate=false and ignoreBlank=false. I managed to get auto focus when the user comes to the page. But I'm facing an issue if the user submit the form without typing any key. In that case, the validator of the TextFormField seems to be not called as well as _phoneNumberControllerListener. So in the RaisedButton.onPress() method, formKey.currentState.validate()=true and the form is successfully submitted. I'm aware that this use case can be valid. But in my case, the user has to fill the phone number field. So I would like to raise an error if the user submit the form without entering a single character.
I think that it can be achieved by exposing the value of provider.isNotValid = false; in the method _phoneNumberControllerListener. Or it could be something like this provider.isNotValid=! ignoreBlank.
Do you think that my request is doable?
Faced with the fact that I can not change the initialized value of the country code. Maybe I'm wrong about something.
Here is an example of what I'm doing
@override
void initState() {
if (widget.phoneNumber != null) {
_parsablePhoneNumber(widget.phoneNumber);
}
super.initState();
}
Future _parsablePhoneNumber(String phoneNumber) async {
if (phoneNumber.isNotEmpty) {
PhoneNumber numberRegionInfo =
await PhoneNumber.getRegionInfoFromPhoneNumber(phoneNumber);
String parsableNumber =
PhoneNumber.getParsableNumber(phoneNumber, numberRegionInfo.dialCode);
setState(() {
_initialCountryCode = numberRegionInfo.isoCode;
});
widget.textEditingController.text = parsableNumber;
}
}
...
initialCountry2LetterCode: _initialCountryCode,
...
The list for choosing country codes is slow and sometimes don't receive touchs...
When using;
PhoneInputSelectorType.DROPDOWN
, it takes about a second to open the list.PhoneInputSelectorType.DIALOG
, slow launch as above, also takes a while to load the content of list too, pausing while scrolling…PhoneInputSelectorType.BOTTOM_SHEET
have serious problems…Tested on Samsung Galaxy A10, on Debug.
I think using a different method to load the elements, and using icon glyphs (like emoticons) instead of images will make a huge difference...
I'm trying to add phone number with country code +91 while i'm trying to type complete number at that time the first digit of mobile number vanished
It would be helpful in some cases to know the number type, so if you can please add this functionality.
Thank you for the nice widget.
i don't want all countries phone code. can you add option for countries list which i want to add.
please provide solution.
If you set autoFormat: true
or set PhoneNumber(isoCode: 'BR', '5167634469')
, it remove lead "5" digit.
gif to demonstrate
It's happen because value.replaceAll(RegExp('^([\\+?${this.dialCode}\\s?]+)'), '')
, it can eat next digits after dialCode, works not only with BR.
I replaced it with value.replaceFirst(RegExp('^([\\+]?${number.dialCode}[\\s]?)', '')
, and it works fine. Replace has been made in phone_number.dart
and as_you_type_formatter.dart
I have done it in my fork
Other than initial ISO which is already implemented it would be nice to have the option to restrict to one country (select box disabled and set to the requested country code) while still having the phone number validation.
Have the option to restrict to specific phone types (mobile, land line, etc).
RTL layout support (Mainly the fact that the phone number cannot be RTL event though the entire layout is RTL the phone number itself (and the phone country code) should be in LTR
e.g. currently in RTL the country code is 1+ instead of +1
When using InternationalPhoneNumberInput.withCustomDecoration you cannot change the error text manually and the is no errorMessage in the constructor. Please allow to modify the error message in this factory as well
Will it be possible to add the country names to the select box and maybe event provide a list of translations by the iso2 code?
Add a search input to easily select a country instead of scrolling through the whole list.
Thanks!
Hi! Great job on this so far!
Would it be possible to add an isRequired
field or something like that? I have a form where I do not require a phone number but it is there if the user wants to put one in. Maybe there is already a way to accomplish this but I couldn't figure it out.
I initially made my home country by default, after which, based on the number I received, I change the country, but as soon as I put my number in there, I get an error that the format is wrong
PhoneNumber _initialPhoneNumber = PhoneNumber(isoCode: 'US');
@override
void initState() {
if (widget.phoneNumber != null) {
_parsablePhoneNumber(widget.phoneNumber);
}
super.initState();
}
Future _parsablePhoneNumber(String phoneNumber) async {
if (phoneNumber.isNotEmpty) {
PhoneNumber numberRegionInfo =
await PhoneNumber.getRegionInfoFromPhoneNumber(phoneNumber);
setState(() {
_initialPhoneNumber = numberRegionInfo;
});
}
}
Auto-validation is enabled in your widget
I have this in my pubspec:
provider: ^4.0.1
If I add intl_phone_number_input, I get this:
No other packages seem to have these kinds of problems. I'm fairy new to Flutter, so I'm not sure the best answer.
Because intl_phone_number_input 0.2.0 depends on provider ^3.2.0 and no versions of intl_phone_number_input match >0.2.0 <0.3.0, intl_phone_number_input ^0.2.0 requires provider ^3.2.0.
So, because therapist_training depends on both provider ^4.0.1 and intl_phone_number_input ^0.2.0, version solving failed.
pub get failed (1; So, because therapist_training depends on both provider ^4.0.1 and intl_phone_number_input ^0.2.0, version solving failed.)
exit code 1
Hi, I caught this problem when choosing a country.
E/flutter ( 5902): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The getter 'owner' was called on null.
E/flutter ( 5902): Receiver: null
E/flutter ( 5902): Tried calling: owner
E/flutter ( 5902): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter ( 5902): #1 Provider.of
package:provider/src/provider.dart:193
E/flutter ( 5902): #2 _InputWidgetState._phoneNumberControllerListener
package:intl_phone_number_input/…/widgets/input_widget.dart:290
E/flutter ( 5902): #3 _InputWidgetState.build.<anonymous closure>
package:intl_phone_number_input/…/widgets/input_widget.dart:415
E/flutter ( 5902): <asynchronous suspension>
E/flutter ( 5902): #4 _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:706
E/flutter ( 5902): #5 _InkResponseState.build.<anonymous closure>
package:flutter/…/material/ink_well.dart:789
E/flutter ( 5902): #6 GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:182
E/flutter ( 5902): #7 TapGestureRecognizer.handleTapUp
package:flutter/…/gestures/tap.dart:486
E/flutter ( 5902): #8 BaseTapGestureRecognizer._checkUp
package:flutter/…/gestures/tap.dart:264
E/flutter ( 5902): #9 BaseTapGestureRecognizer.acceptGesture
package:flutter/…/gestures/tap.dart:236
E/flutter ( 5902): #10 GestureArenaManager.sweep
package:flutter/…/gestures/arena.dart:156
E/flutter ( 5902): #11 GestureBinding.handleEvent
package:flutter/…/gestures/binding.dart:222
E/flutter ( 5902): #12 GestureBinding.dispatchEvent
package:flutter/…/gestures/binding.dart:198
E/flutter ( 5902): #13 GestureBinding._handlePointerEvent
package:flutter/…/gestures/binding.dart:156
E/flutter ( 5902): #14 GestureBinding._flushPointerEventQueue
package:flutter/…/gestures/binding.dart:102
E/flutter ( 5902): #15 GestureBinding._handlePointerDataPacket
package:flutter/…/gestures/binding.dart:86
E/flutter ( 5902): #16 _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter ( 5902): #17 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter ( 5902): #18 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter ( 5902): #19 _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter ( 5902): #20 _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
E/flutter ( 5902):
Hey!
Thanks for the package!
Everything is working as expected, except for the differents assets that fail to load. I gave you a screenshot of the error I'm getting, it seems to be having issues with the ImageProvider as you can see.
Any idea if you can fix it ? Or if it's possible to turn off the images ? I don't really need them anyway
thanks!
I stored a valid phone number in secure storage and want to get it as an initial value when a user reopen the page. I can't find anywhere to put this value in this widget.
I am currently using this in a form where I need to set the initial value. Would you be able to expose that at the user level?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.