international_phone_input 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 97

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

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.

[1.0.4] #

  • Add optional decoration object

  • Add optional border parameter to be set as InputBorder on the decoration object

[1.0.3] #

  • Add optional labelText and labelStyle parameters

  • Only show enabled countries

[1.0.2] #

  • Add widget with text input (no dropdown list)

[1.0.1] #

  • Add hint/error parameters for customization

[1.0.0] #

  • Bump version

[0.0.5] #

  • Add example project

[0.0.4] #

  • Emit empty string value to onchange listener if phone number is invalid.

[0.0.3] #

  • Improvements.

[0.0.2] #

  • Indentation fix.

[0.0.1] #

  • Initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:international_phone_input/international_phone_input.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Example Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String phoneNumber;
  String phoneIsoCode;
  bool visible = false;
  String confirmedNumber = '';

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

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('International Phone Input Example'),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            Spacer(flex: 1),
            InternationalPhoneInput(
              onPhoneNumberChange: onPhoneNumberChange,
              initialPhoneNumber: phoneNumber,
              initialSelection: phoneIsoCode,
              enabledCountries: ['+233', '+1'],
              labelText: "Phone Number",
            ),
            SizedBox(height: 20),
            InternationalPhoneInput(
              decoration: InputDecoration.collapsed(hintText: '(123) 123-1234'),
              onPhoneNumberChange: onPhoneNumberChange,
              initialPhoneNumber: phoneNumber,
              initialSelection: phoneIsoCode,
              enabledCountries: ['+233', '+1'],
              showCountryCodes: false,
              showCountryFlags: true,
            ),
            SizedBox(height: 20),
            Container(
              width: double.infinity,
              height: 1,
              color: Colors.black,
            ),
            SizedBox(height: 50),
            InternationalPhoneInputText(
              onValidPhoneNumber: onValidPhoneNumber,
            ),
            Visibility(
              child: Text(confirmedNumber),
              visible: visible,
            ),
            Spacer(flex: 2)
          ],
        ),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  international_phone_input: ^1.0.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:international_phone_input/international_phone_input.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
94
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
97
Learn more about scoring.

We analyzed this package on Jul 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:international_phone_input/international_phone_input.dart that imports:
  • package:international_phone_input/src/international_phone_input_text.dart that imports:
  • package:international_phone_input/src/phone_service.dart that imports:
  • package:libphonenumber/libphonenumber.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:international_phone_input/international_phone_input.dart that imports:
  • package:international_phone_input/src/international_phone_input_text.dart that imports:
  • package:international_phone_input/src/phone_service.dart that imports:
  • package:libphonenumber/libphonenumber.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:international_phone_input/international_phone_input.dart that imports:
  • package:international_phone_input/src/international_phone_input_text.dart that imports:
  • package:international_phone_input/src/phone_service.dart that imports:
  • package:libphonenumber/libphonenumber.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:international_phone_input/international_phone_input.dart that imports:
  • package:international_phone_input/src/international_phone_input_text.dart that imports:
  • package:international_phone_input/src/phone_service.dart that imports:
  • package:libphonenumber/libphonenumber.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • international_phone_input that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
flutter 0.0.0
libphonenumber ^1.0.0 1.0.1
Transitive dependencies
built_collection 4.3.2
built_value 7.1.0
collection 1.14.12 1.14.13
fixnum 0.10.11
matcher 0.12.9
meta 1.1.8 1.2.2
path 1.7.0
quiver 2.1.3
sky_engine 0.0.99
stack_trace 1.9.5
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test
test ^1.6.0