Giter Club home page Giter Club logo

flutter-international-phone-input's Introduction

international_phone_input

International Phone Number Input For Flutter

Usage

Just put the component in your application.

import 'package:international_phone_input/international_phone_input.dart';

String phoneNumber;
String phoneIsoCode;

void onPhoneNumberChange(String number, String internationalizedPhoneNumber, String isoCode) {
    setState(() {
       phoneNumber = number;
       phoneIsoCode = isoCode;
    });
}

// Default Widget with dropdown list
@override
 Widget build(BuildContext context) => Scaffold(
     body: Center(
       child: InternationalPhoneInput(
          onPhoneNumberChange: onPhoneNumberChange, 
          initialPhoneNumber: phoneNumber,
          initialSelection: phoneIsoCode,
          enabledCountries: ['+233', '+1']
       ),
     ),
 );

// Widget with text input only

 onValidPhoneNumber(
      String number, String internationalizedPhoneNumber, String isoCode) {
    setState(() {
      confirmedNumber = internationalizedPhoneNumber;
    });
  }

@override
 Widget build(BuildContext context) => Scaffold(
     body: Center(
       child:  InternationalPhoneInputText(
         onValidPhoneNumber: onValidPhoneNumber,
        ),
     ),
 );

// Widget with decoration
// Using decoration overwrites other styles such as hintStyle, hintText, etc.

@override
 Widget build(BuildContext context) => Scaffold(
     body: Center(
       child: InternationalPhoneInput(
          decoration: InputDecoration.collapsed(hintText: '(416) 123-4567'),
          onPhoneNumberChange: onPhoneNumberChange, 
          initialPhoneNumber: phoneNumber,
          initialSelection: phoneIsoCode,
          enabledCountries: ['+233', '+1'],
          showCountryCodes: false
       ),
     ),
 );

Customization

Here is a list of properties available to customize the widget:

Name Type Description
initialPhoneNumber String used to set initial phone number
initialSelection String used to set initial country code
errorText String use this to set an error message
hintText String sets hint
labelText String sets label
errorStyle TextStyle style applied to error message
hintStyle TextStyle style applied to hint
labelStyle TextStyle style applied to label
errorMaxLines int the maximum number of lines user can type
enabledCountries List the list of enabled countries to display
decoration InputDecoration decoration applied to the TextField widget
showCountryCodes bool shows the country code (default true)
showCountryFlags bool shows. the country flags (default true)
dropdownIcon Widget use this to customize dropdown icon

Contributions

Contributions of any kind are more than welcome! Feel free to fork and improve international_phone_input in any way you want, make a pull request, or open an issue.

flutter-international-phone-input's People

Contributors

buraktabn avatar drakebw avatar el-etreby avatar evilnii avatar niinyarko avatar quang-le avatar thallessantos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

flutter-international-phone-input's Issues

Issue in debug mode

when i am running my app in debug mode. I am getting following error

`The following NoSuchMethodError was thrown while dispatching notifications for TextEditingController:
The getter 'code' was called on null.
Receiver: null
Tried calling: code

When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1 _InternationalPhoneInputState._validatePhoneNumber
package:international_phone_input/src/international_phone_input.dart:127
#2 ChangeNotifier.notifyListeners
package:flutter/…/foundation/change_notifier.dart:207
#3 ValueNotifier.value=
package:flutter/…/foundation/change_notifier.dart:274
#4 EditableTextState._value=
package:flutter/…/widgets/editable_text.dart:1459
...
The TextEditingController sending notification was: TextEditingController#3cc2e(TextEditingValue(text: ┤9├, selection: TextSelection(baseOffset: 1, extentOffset: 1, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1)))`

Phone number printing old value after deleting last digit

The phone number prints correctly once it is verified. However if I delete a single digit from the phone number so that it is no longer valid, onPhoneNumberChange runs twice. First an empty string is printed (as expected) but right after that it prints the entire number as if nothing was deleted from the end. Here's my method

void onPhoneNumberChange(String number, String internationalizedPhoneNumber, String isoCode) {
setState(() {
      phoneNumber = internationalizedPhoneNumber;
      print(number);
    });
  }

InternationalPhoneInput(
          onPhoneNumberChange: onPhoneNumberChange,
          initialPhoneNumber: phoneNumber,
          initialSelection: 'US',
        ),

Search and Sort functionality required

Hi, please provide this sorting functionality or search functionality for countries, it will be difficult to user to scroll through all the countries. Right now, the sorting is based on country names but we are not displaying country names. At least, give option to display country name.
thanks.

Trinidad And Tobago case

I was validating a number from Trinidad and Tobago, the country code is +1, but to call you have to use +1868, so if I put the remaining 7 digits it shows the invalid format error, what can I do?
Thanks in advance

Invalid
image

Valid
image

adding fillColor & filled to Textfields

Hello,
thanks for the component, it is great!
I would like to add these properties to the TextFields

**[fillColor, Opacity, and filled]

InputDecoration(
fillColor: Colors.transparent.withOpacity(0.5),
filled:true,**

can you add it or if i do it on a branch will you merge it into the package? I dont have much experience with contributing!

Thanks :)

Andy ink

Null Safety

migrate this pub in null safety.

if you are not interested in null safety, please declare in pub.dev for no longer provide null safety

Thank You

Show a countries that i want to show

Hi, your library very nice.. but how i can show a few country in dropdown? not displaying all countries only a few that I want to show
Thank you,

No labelText Option

I would like to add a label to the TextField widget in the InternationalPhoneInput widget. Allowing a positional parameter to pass in an optional labelText would add this feature quite easily

Set State issue

I am getting this error " Unhandled Exception: setState() called after dispose(): _InternationalPhoneInputState#a2d65 "
how can I solve this?

Previous answer issue

Gives last user input when a number in textFeild is one number less than the required size && this happens when back button in
the phone is pressed instead of the tick button on the keyboard.
That is even if the TextFeild has only 9 letters we get an output of 10 that is the previous valid one which is kind of an Error for validation
(NB: New to flutter, so I can't say am right, correct me if am wrong )

Controlling max characters would be super useful

It would be super useful to limit the number of digits that can be inputted into the field.
like

TextField(
  maxLength: widget.maxDigits??null,
)

I know the code but I have never contributed before. Please, someone, add this functionality or help me do it.

Option for phone validation

User wants an option for using phone validation. There might be a case to input custom numbers that may not be able to validate by this plugin.

onValidPhoneNumber

How do I make sure that the number phone is correct and not empty in method InternationalPhoneInput ?

Add Focus Node to Mobile Field

There is no way one can determine when the field is focused or request focus on the field without doing much. I would suggest this attribute passed on through a property or some sort.

Suggestions ..

  1. try to make (const widgets list of the countries) instead of building (the countries list) every time we press the button , it will make the plugin very fast , and improve the performance of the app ..

  2. add auto detect country code using (Location service) .. , i can help .., but i never developed a plugin , and don't know how to upload it ..

  3. in the filed using this code will deted the system country code (imported from dart:io package)
    initialCountry2LetterCode: Platform.localeName.split('_')[1].toString()

Search Bar on Country Code

Hello brother,
I'm very appreciative to use your library, it's very convenient and useful.
But I have a problem when I use your library, can you help me fix it? Thanks a lot.
I'm quite hard to find my country on your drop down list, so I think that if you can add search bar on country finding drop down list, it will help better user experience.
Thanks for reading my issue.
Best regards,
Thank you.

unable to select country based on location

i am using gelocator plugin to get the current location. So, based on that i need to make the initialSelection corresponding to the location countryISO. But when i tried its not updating.

Can i know what could be wrong?
Below is my code to set the initialSelection.

 List<Placemark> p = await geolocator.placemarkFromCoordinates(
          _currentPosition.latitude, _currentPosition.longitude);
      Placemark place = p[0];
      setState(() {
        countryCode = place.isoCountryCode;
      });
InternationalPhoneInput(
             onPhoneNumberChange: _onPhoneNumberChanged,
             initialSelection: countryCode,
             errorText:"Please type a valid phone number",
             errorMaxLines:4,
           ),);

adding +47 gives multiple duplicates

                        InternationalPhoneInput(
                          onPhoneNumberChange: onPhoneNumberChange,
                          initialPhoneNumber: phoneNumber,
                          initialSelection: phoneIsoCode,
                          enabledCountries: ['+46', '+47'],
                        ),

bug

will give me 3 flags of norway

Dark mode support

just replace Colors.white in input_widget.dart ...

with this:
MediaQuery.of(context).platformBrightness == Brightness.dark ? Color(0xff212121) : Colors.white

for dark mode ..

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.