A simple and customizable flutter package for international phone number input
* As You Type Formatter: The Package now formats the input to it's selected national format
* You can now disable input formatting by setting inputFormat to false
* Replaced TextField with
* AutoValidate
* TextStyle
* onInputChanged now returns a new PhoneNumber Model
* You can create a PhoneNumber object from PhoneNumber.getRegionInfoFromPhoneNumber(String phoneNumber, [String isoCode]);
* You can now parse phoneNumber by calling PhoneNumber.getParsableNumber(String phoneNumber, String isoCode) or `PhoneNumber Reference`.parseNumber()
* Custom list of countries e.g. ['NG', 'GH', 'BJ' 'TG', 'CI']
String phoneNumber = '+234 500 500 5005';
PhoneNumber number = await PhoneNumber.getRegionInfoFromPhoneNumber(phoneNumber);
String parsableNumber = number.parseNumber();
`controller reference`.text = parsableNumber
PhoneNumber.getRegionInfoFromPhoneNumber(String phoneNumber, [String isoCode])
Could throw an Exception if the phoneNumber isn't recognised its a good pattern to pass the country's isoCode or have '+' at the beginning of the string
s/n | Constructor |
---|---|
1 | InternationalPhoneNumberInput |
2 | InternationalPhoneNumberInput.withCustomDecoration |
3 | InternationalPhoneNumberInput.withCustomBorder |
InternationalPhoneNumberInput({
Key key,
@required this.onInputChanged,
this.onInputValidated,
this.focusNode,
this.textFieldController,
this.onSubmit,
this.keyboardAction,
this.countries,
this.textStyle,
this.inputBorder,
this.inputDecoration,
this.initialCountry2LetterCode = 'NG',
this.hintText = 'Phone Number',
this.autoValidate = false,
this.formatInput = true,
this.errorMessage = 'Invalid phone number',
});
Parameter | Datatype | Initial Value | Default [1] | Decoration [2] | CustomBorder [3] |
---|---|---|---|---|---|
onInputChange | function(PhoneNumber) | null | ✔️ | ✔️ | ✔️ |
onInputValidated | function(string) | null | ✔️ | ✔️ | ✔️ |
focusNode | FocusNode | null | ✔️ | ✔️ | ✔️ |
textFieldController | TextEditingController | TextEditingController() | ✔️ | ✔️ | ✔️ |
onSubmit | Function() | null | ✔️ | ✔️ | ✔️ |
keyboardAction | TextInputAction | null | ✔️ | ✔️ | ✔️ |
countries | List | null | ✔️ | ✔️ | ✔️ |
textStyle | TextStyle | null | ✔️ | ✔️ | ✔️ |
inputBorder | InputBorder | null | ✔️ | ❌ | ✔️ |
inputDecoration | InputDecoration | null | ✔️ | ✔️ | ❌ |
initialCountry2LetterCode | String | NG | ✔️ | ✔️ | ✔️ |
hintText | String | Phone Number | ✔️ | ❌ | ✔️ |
autoValidate | boolean | true | ✔️ | ✔️ | ✔️ |
formatInput | boolean | true | ✔️ | ✔️ | ✔️ |
errorMessage | String | Invalid phone number | ✔️ | ❌ | ✔️ |
If you encounter any problem or the library is missing a feature feel free to open an issue. Feel free to fork, improve the package and make pull request.
A special thanks to niinyarko