Giter Club home page Giter Club logo

intl_phone_number_input's Introduction

Intl Phone Number Input

A simple and customizable flutter package for inputting phone number in intl / international format uses Google's libphonenumber

CustomDecoration CustomBorder Default
Screenshot_1587652933 Screenshot_1587652933 Screenshot_1587652933
Web

What's new

  • Updated libphonenumber and PhoneNumberToCarrierMapper on Android
  • Removed dependency on libphonenumber
  • Switch from libphonenumber-iOS to PhoneNumberKit on iOS
  • Update libphonenumber.js file
  • Depreciating getNameForNumber in future updates

Features

  • Web support.
  • Support for RTL languages
  • Selector mode dropdown, bottom sheet and dialog
  • As You Type Formatter: formats inputs to its selected international format
  • Get Region Info with PhoneNumber.getRegionInfoFromPhoneNumber(String phoneNumber, [String isoCode]);
  • Format PhoneNumber with 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

Web Support

In your app directory, edit web/index.html to add the following

<!DOCTYPE html>
<html>
    <head>
        ...
    </head>
    <body>
    
        ...

        <script src="assets/packages/libphonenumber_plugin/js/libphonenumber.js"></script>
        <script src="assets/packages/libphonenumber_plugin/js/stringbuffer.js"></script>

        ...

        <script src="main.dart.js" type="application/javascript"></script>
    </body>
</html>

Or checkout /example folder from Github.

Note

    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

isoCode could be null if PhoneNumber is not recognised

Usage

Constructors

s/n Constructor
1 InternationalPhoneNumberInput

Available Parameters

InternationalPhoneNumberInput({
    Key key,
      this.selectorConfig = const SelectorConfig(),
      @required this.onInputChanged,
      this.onInputValidated,
      this.onSubmit,
      this.onFieldSubmitted,
      this.validator,
      this.onSaved,
      this.textFieldController,
      this.keyboardAction,
      this.keyboardType = TextInputType.phone,
      this.initialValue,
      this.hintText = 'Phone number',
      this.errorMessage = 'Invalid phone number',
      this.selectorButtonOnErrorPadding = 24,
      this.spaceBetweenSelectorAndTextField = 12,
      this.maxLength = 15,
      this.isEnabled = true,
      this.formatInput = true,
      this.autoFocus = false,
      this.autoFocusSearch = false,
      this.autoValidateMode = AutovalidateMode.disabled,
      this.ignoreBlank = false,
      this.countrySelectorScrollControlled = true,
      this.locale,
      this.textStyle,
      this.selectorTextStyle,
      this.inputBorder,
      this.inputDecoration,
      this.searchBoxDecoration,
      this.textAlign = TextAlign.start,
      this.textAlignVertical = TextAlignVertical.center,
      this.scrollPadding = const EdgeInsets.all(20.0),
      this.focusNode,
      this.cursorColor,
      this.autofillHints,
      this.countries
    });
SelectorConfig({
    this.selectorType = PhoneInputSelectorType.DROPDOWN,
    this.showFlags = true,
    this.useEmoji = false,
    this.backgroundColor,
    this.countryComparator,
    this.setSelectorButtonAsPrefixIcon = false,
    this.useBottomSheetSafeArea = false,
});
Parameter Datatype Initial Value
onInputChanged function(PhoneNumber) null
onSaved function(PhoneNumber) null
onInputValidated function(bool) null
focusNode FocusNode null
textFieldController TextEditingController TextEditingController()
onSubmit Function() null
keyboardAction TextInputAction null
keyboardType TextInputType TextInputType.phone
countries List null
textStyle TextStyle null
selectorTextStyle TextStyle null
inputBorder InputBorder null
inputDecoration InputDecoration null
initialValue PhoneNumber null
hintText String Phone Number
selectorButtonOnErrorPadding double 24
spaceBetweenSelectorAndTextField double 12
maxLength integer 15
isEnabled boolean true
autoFocus boolean false
autoValidateMode AutoValidateMode AutoValidateMode.disabled
formatInput boolean true
errorMessage String Invalid phone number
selectorConfig SelectorConfig SelectorConfig()
ignoreBlank boolean false
locale String null
searchBoxDecoration InputDecoration null
textAlign TextAlign TextAlign.start
textAlignVertical TextAlignVertical TextAlignVertical.center
scrollPadding EdgeInsets EdgeInsets.all(20.0)
countrySelectorScrollControlled boolean true
cursorColor String \ null
autofillHints Iterable null

Selector Types

DROPDOWN BOTTOMSHEET DIALOG
Screenshot_1587652933 Screenshot_1587652933 Screenshot_1587652933

Testing

Widget Key parameters and Helper classes are now available for integration testing check out this example ๐ŸŽฏ Integration Testing Example

Contributions

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.

Co-contributors

Interested in becoming a co-contributors checkout this link for more info discussions/201

Contributors

Made with contributors-img.

Dependencies

Credits

A special thanks to niinyarko

FAQ

  • For discussions and frequent question and concerns, check here

intl_phone_number_input's People

Contributors

alr2413 avatar bdtren avatar bynalab avatar ccjy avatar clemax avatar dannyalbuquerque avatar darkstarx avatar eboye avatar farhansyedain avatar gsi-yoan avatar guyzk avatar moazelsawaf avatar muhammadusamasiddiqui avatar natintosh avatar nhuanvd avatar nikostsesmelis avatar piotrszych avatar raffa-12 avatar renannery avatar ricardorb avatar sarbogast avatar sgehrman avatar susheelkaram avatar tekno0ryder avatar tiancaidao avatar uuttssaavv avatar valerii-hubskyi avatar viktordineout avatar vishal-android-freak avatar zeusbaba avatar

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.