Giter Club home page Giter Club logo

intl_phone_field's Introduction

International Phone Field Package

pub package CI License: MIT

A customised Flutter TextFormField to input international phone number along with country code.

This widget can be used to make customised text field to take phone number input for any country along with an option to choose country code from a dropdown.

⚠️ The package is deprecated and this repository is no longer maintained ⚠️

As of June 2021, I, @marcaureln, have been maintaining this Flutter package initially created by @vanshg395. Regrettably, Vansh has been unresponsive, and I am unable to release new versions (the last release is 6 months old as of writing).

Considering this, I recommend users to explore alternatives on pub.dev or, if interested, fork this repository for continued support. Life can be hectic, and I wish Vansh is doing well.

Thank you for your understanding and continued support.

Old Readme

Screenshots

Installing

To use this package:

Run this command:

flutter pub add intl_phone_field

Or, add the following to your pubspec.yaml file:

dependencies:
  intl_phone_field: ^<latest_version>

Sometimes you may want to use the latest version of the package, instead of a published version. To do that, use the git syntax:

dependencies:
  intl_phone_field:
    git:
      url: git://github.com/vanshg395/intl_phone_field.git
      ref: master

How to Use

Simply create a IntlPhoneField widget, and pass the required params:

IntlPhoneField(
    decoration: InputDecoration(
        labelText: 'Phone Number',
        border: OutlineInputBorder(
            borderSide: BorderSide(),
        ),
    ),
    initialCountryCode: 'IN',
    onChanged: (phone) {
        print(phone.completeNumber);
    },
)

Use initialCountryCode to set an initial Country Code.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Comment on Issue or Pull Request, asking @all-contributors to add a contributor:

@all-contributors please add @<username> for <contributions>

<contributions>: See the Emoji Key (Contribution Types Reference) for a list of valid contribution types.

Maintainers

Contributors

Vansh Goel
Vansh Goel

💻
KNO3
KNO3

💻
Ling Li
Ling Li

💻
Anggara Putra Pratama
Anggara Putra Pratama

💻
JJ Geewax
JJ Geewax

💻
Keval Prajapati
Keval Prajapati

💻
Guillaume Launay
Guillaume Launay

💻
hans.huang
hans.huang

💻 📖
Gregor Weber
Gregor Weber

💻
Ooi Han Yi
Ooi Han Yi

💻
Jimmy Forrester-Fellowes
Jimmy Forrester-Fellowes

💻

LICENSE

This project is licensed under the MIT license. See LICENSE for more information.

intl_phone_field's People

Contributors

2000calories avatar 4mitabh avatar aliasgarlabs avatar allcontributors[bot] avatar almasco123 avatar anggaraputrapratama avatar bclarksoftware avatar bilalraad avatar devbrandonlong avatar donzo24 avatar edner84 avatar goatiful avatar grafst avatar grooviz avatar iampato avatar ideepakyadav avatar jino-gigco avatar kanekt avatar launay12u avatar lingster avatar marcaureln avatar meiraxx avatar skpraharaj avatar subair-zufi avatar tareqamenahdev avatar tritao avatar vanshg395 avatar waelahmed99 avatar yaashwardhan avatar zaharl 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  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

intl_phone_field's Issues

Incorrect phone number legnth for qatar

If you select Qatar and then input the number it allows 10 characters when actually they should be 8.

Please fix this, this issue is also common with many other country lengths.

Erro on the new version

A receive this error on calling the IntlPhoneField():

The method 'copyWith' was called on null.
Receiver: null
Tried calling: copyWith(counter: Instance of 'SizedBox')
The relevant error-causing widget was
    IntlPhoneField 

I tried to call it a Column, Wrap and inside a simple container.

Add max length

Hey bro,

Thanks for the good package!
Would it be possible to add a parameter to the list 'maxLength' just like in the TextFormField ?

Thanks!

Update deprecated properties in showDialog

The intl_phone_field.dart file is using the method showDialog(context: context, useRootNavigator: false, child : ...) and child is deprecated. It should be updated to builder.

Incorrect phone lenght for Mauritania

Hello,
Thank you for your useful plugin.
I want to mention that the length of phone number in Mauritania is 8 not 7.
We cannot use the plugin without rectifying this.
Thank you.

Country name change.

Please note Swaziland has been changed to Eswatini, Eswatini is the new name of the country, please update.

prefill number (initial value)

Feature request: Ability to prefill the number by using an API like the one in TextFormField (initialValue).

Used case: The requirement is when the number entered earlier can be edited.

If this is not in works already, I am happy to submit a PR.

Thanks!

Label exposure

Would be nice to have a configuration area where you can modify the texts like : "Invalid phone Number" and other tags .. that way people could change easily.

I

Add the ability to disable the country list dropdown

It could be great to have a similar property to readOnly or enabled for the country list dropdown.
I need the user to enter its phone number, and once validated I need to keep the IntlPhoneField widget but without the ability to change it. So I disable the textfield, but I can't disable the country list drop down, even if I hide the cursor icon using showDropdownIcon=false.

As a quick fix I tried to change the countries array after validating the phone number and set it to one unique value (the currently selected country) so even if the user access the dropdown he won't have the ability to change the country.
Unfortunately, this doesn't seems to work as the initial value of countries seems to be permanent, even when updating it in a stateful widget.

BREAKING, Incorrect mobile required length

After the latest update the widget requires 9 digits for example where a country needs 10 (Egypt) which how it was initially, i also want to remove the x/9 validator but to no avail.

Validation Logic is faulty

The Validation logic doesn't check according to the selected country's max length. It compares to constant value 10. Which fails on several country selection validations. Thus auto validation doesn't work.
Here is the code from the package.

validator = widget.autoValidate ? ((value) => value != null && value.length != 10 ? 'Invalid Mobile Number' : null) : widget.validator;

Flag and number don't update according to initial value

If we provide an initial value or a controller with a text prepopulated, then the flag and number don't update according to the provided value.

For example if initValue="+33123456789"
the flag should be the French one and the displayed number should be "123456789".

Instead it displays the US flag or whatever is the initialCountryCode and the displayed number remains "+33123456789"

Can't disable the small number indicator under the input

I want to hide the number under the input field

image

code

IntlPhoneField(
                      decoration: InputDecoration(
                        hintText: "Phone Number",
                        hintStyle: TextStyle(color: Colors.grey[600], fontWeight: FontWeight.bold),
                        filled: true,
                        fillColor: Colors.white,
                        border: OutlineInputBorder(
                          borderSide: BorderSide(),
                        ),
                      ),
                      style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black),
                      initialCountryCode: 'BD',
                      onChanged: (phone) {
                        setState(() {
                          UserData.phone = phone.completeNumber;
                        });
                        print(phone.completeNumber);
                      },
                    ),

issue in changing dropdown icon position

Thanks for the package!
Wanted to change the position of the dropdown icon from the left side of the flag and number to the right of them but didn't get a way of doing it.

Egyptian phone number isn't valid

When I tried to add Egyptian number, the field accepted only 9 inputs, although the numbers should be 10 inputs.
(+20) 1234567890

Country picker pop the wrong page on the stack

The problem is when using the widget in a page already on the stack.
We can resolve the issue by
adding the following code in file int_phone_field.dart

Future _changeCountry() async {
filteredCountries = countries;
await showDialog(
useRootNavigator: false,

some times backspace doesn't work

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)

Feature: Add support for setting the CountryCode

My app already has phone number coming from async, so i need to be able to set countryCode dynamically.
But initialCountryCode, only sets the initial value, if you change it later, the widget will NOT be rebuild.

Incorrect validation

The current validation expects exactly ten digits, which is not universally correct. According to E.164, there might be up to 12 digits in the number, but possibly less.

Max Length and Auto-Validate

The maximum length as a default is set to 10, however many international phone numbers are longer than 10 digits. The auto-validate method then just checks if the phone number is less than 10 digits (not max length, just the number 10). This should vary depending on the country code and be automatically updated

Incorrect phone number legnth for Pakistan

If you select pakistan and then input number it allows 11 charachters when actually they should be 10.

Please fix this, this issue is also common with many other country lengths. If you fix these issues for all countries it will be the most popular package in pub.dev

No named parameter with the name 'child'

/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/intl_phone_field-1.4.2/lib/intl_phone_field.dart:192:7: Error: No named parameter with the name 'child'.
child: StatefulBuilder(
^^^^

enabled argument where is it?

sometimes you need to disable the input field for example in case of Login we don't need the field of number, we just need the Username & password. especially if we do Animation, so the Field is here but we don't need it in login.

GPLv3 -> LGPLv3?

Hi Vansh,

Looks like you did some great work with this library. Unfortunately, I've yet to test it because the GPLv3 is too restrictive for me. On that note, I'm hardly the only one that cannot use your library due to its strict licensing. Is there a concrete reason for you to have chosen the GPLv3? Aside from your noble free software goals, the license will only hurt this library's popularity, especially when there are other libraries out there solving the same problem (e.g. https://pub.dev/packages/intl_phone_number_input). Your library seems to have a nicer API though that's why I'm asking. Would you mind changing it to some less restrictive license like the LGPLv3, MIT or Apache v2? Thanks.

Kind regards,
Jonas

Doesn't reflect the Country Code on Firebase resulting in Invalid format!

I was just using this package and this is what I did

IntlPhoneField(
style: TextStyle(fontSize: 16.0),
autofocus: true,
showDropdownIcon: false,
controller: phoneController, // <= on passing this phoneController to Firebase, it only passes the phone number
decoration: InputDecoration(
labelText: 'Phone Number',
border: UnderlineInputBorder(),
),
initialCountryCode: 'IN',
onChanged: (phone) {
print(phone.completeNumber);
},
onCountryChanged: (phone) {
print('Country code changed to: ' + phone.countryCode);
},
),

So am I doing anything wrong?

example in flutter web doesnot work

run the example app in flutter web try to change the country

error:

Error: setState() called after dispose(): _IntlPhoneFieldState#e0cb6(lifecycle state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().

flutter version:

Flutter 1.20.0-3.0.pre.63 • channel master • https://github.com/flutter/flutter.git
Framework • revision 1e6e7150f3 (6 days ago) • 2020-06-26 12:01:59 +0800
Engine • revision 22b099bc63
Tools • Dart 2.9.0 (build 2.9.0-19.0.dev ea87c9b01a)

Feature: trigger onChange event when the flag dropdown value is changed

Hello guys, thank you for the useful widget.
Do you plan to integrate a trigger for onChange event? I think it'll be good improvement since currently if the user enters the number and after that changes the flag the last triggered onChange event will be with the previous selected flag.

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.