intl_phone_number_input 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 89

Intl Phone Number Input #

A single and customizable flutter package for international phone number input

What's new #

* Added focus node
* Custom list of countries e.g. ['NG', 'GH', 'BJ' 'TG', 'CI']
* Country Flag and Logo now formatted

Usage #

Constructors #

s/nConstructor
1InternationalPhoneNumberInput
2InternationalPhoneNumberInput.withCustomDecoration
3InternationalPhoneNumberInput.withCustomBorder

Available Parameters #

InternationalPhoneNumberInput({
@required onInputChange,
      onInputValidated,
      focusNode,
      countries,
      inputBorder,
      inputDecoration,
      initialCountry2LetterCode = 'NG',
      hintText = '(800) 000-0001 23',
      shouldParse = true,
      shouldValidate = true,
      formatInput = true,
      errorMessage = 'Invalid phone number'});
ParameterDatatypeInitial ValueDefault [1]Decoration [2]CustomBorder [3]
onInputChangefunction(string)null✔️✔️✔️
onInputValidatedfunction(string)null✔️✔️✔️
focusNodeFocusNodenull✔️✔️✔️
countriesListnull✔️✔️✔️
inputBorderInputBordernull✔️✔️
inputDecorationInputDecorationnull✔️✔️
initialCountry2LetterCodeStringNG✔️✔️✔️
hintTextString(800) 000-0001 23✔️✔️
shouldParsebooleantrue✔️✔️✔️
shouldValidatebooleantrue✔️✔️✔️
formatInputbooleantrue✔️✔️✔️
errorMessageStringInvalid phone number✔️✔️

Examples #

InternationalPhoneNumberInput(
 onInputChanged: onPhoneNumberChanged,
);

Media 1|100x200,20%

InternationalPhoneNumberInput(
  onInputChanged: onPhoneNumberChanged,
  shouldParse: false,
  );

Media 2

InternationalPhoneNumberInput(
  onInputChanged: onPhoneNumberChanged,
  shouldParse: true,
  shouldValidate: true,
  initialCountry2LetterCode: 'US',
  hintText: 'Insert phone number',
  );

Media 3

InternationalPhoneNumberInput.withCustomBorder(
  onInputChanged: onPhoneNumberChanged,
  inputBorder: OutlineInputBorder(),
  hintText: '(100) 123-4567 8901',
  initialCountry2LetterCode: 'US',
  errorMessage: 'Wrong number',
);

Media 4

InternationalPhoneNumberInput.withCustomDecoration(
  onInputChanged: onPhoneNumberChanged,
  initialCountry2LetterCode: 'US',
  inputDecoration: InputDecoration(
    border: OutlineInputBorder(
    borderRadius: BorderRadius.all(
      Radius.circular(40),
      ),
    ),
  ),
);

Media 4

InternationalPhoneNumberInput.withCustomDecoration(
  onInputChanged: onPhoneNumberChanged,
  onInputValidated: onInputChanged,
  initialCountry2LetterCode: 'US',
  inputDecoration: InputDecoration(
    hintText: 'Enter phone number',
    errorText: valid ? null : 'Invalid',
    border: OutlineInputBorder(
      borderRadius: BorderRadius.all(
        Radius.circular(40),
      ),
    ),
  ),
);

Media 6

Dependencies #

Credits #

A special thanks to niinyarko

[0.1.0]

  • Minor bug fixed
  • What's new #

    • Added focus node
    • Custom list of countries e.g. ['NG', 'GH', 'BJ' 'TG', 'CI']
    • Country Flag and Logo now formatted

[0.0.10]

  • Minor changes to the source file

[0.0.9]

  • Critical bug fixed caused by changing source files and packages

[0.0.8]

  • Minor changes to the source file
  • Added example
  • Updated README.md
  • Added examples to README.md

[0.0.7]

  • Critical bug fixed
  • Updated README.md

[0.0.6]

  • Updated README.md
  • Fixed issues with text input not validating
  • Fixed issues with text input not parsing

[0.0.5]

  • Critical bug fixed
  • Removed example
  • Fixed countries.json assets not loading

[0.0.4]

  • Critical bug fixed
  • Fixed image assets not loading

[0.0.3]

  • Critical bug fixed
  • Added examples
  • Fixed image assets not loading

[0.0.2]

  • Critical bug fixed
  • Updated README.md

[0.0.1]

Initial project release #
  • Updated README.md
  • Added support for custom input decoration
  • Added support for custom input border

example/README.md

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

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Intl Phone Number Input'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String phoneNumber = '';
  bool valid = false;

  void onPhoneNumberChanged(String phoneNumber) {
    print(phoneNumber);
    setState(() {
      this.phoneNumber = phoneNumber;
    });
  }

  void onInputChanged(bool value) {
    print(value);
    setState(() {
      valid = value;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: SingleChildScrollView(
        child: Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0),
                child: Text(
                  'Default Constructor',
                  style: Theme.of(context)
                      .primaryTextTheme
                      .body1
                      .apply(fontSizeFactor: 1.5, color: Colors.black),
                ),
              ),
              InternationalPhoneNumberInput(
                onInputChanged: onPhoneNumberChanged,
              ),
              Container(
                padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0),
                child: Text(
                  'Default Constructor with parsing set to false',
                  style: Theme.of(context)
                      .primaryTextTheme
                      .body1
                      .apply(fontSizeFactor: 1.5, color: Colors.black),
                ),
              ),
              InternationalPhoneNumberInput(
                onInputChanged: onPhoneNumberChanged,
                shouldParse: false,
              ),
              Container(
                padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0),
                child: Text(
                  'Default Constructor with initialCountry set and hint text',
                  style: Theme.of(context)
                      .primaryTextTheme
                      .body1
                      .apply(fontSizeFactor: 1.5, color: Colors.black),
                ),
              ),
              InternationalPhoneNumberInput(
                onInputChanged: onPhoneNumberChanged,
                shouldParse: true,
                shouldValidate: true,
                initialCountry2LetterCode: 'US',
                hintText: 'Insert phone number',
              ),
              Container(
                padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0),
                child: Text(
                  'Custom Border ',
                  style: Theme.of(context)
                      .primaryTextTheme
                      .body1
                      .apply(fontSizeFactor: 1.5, color: Colors.black),
                ),
              ),
              InternationalPhoneNumberInput.withCustomBorder(
                onInputChanged: onPhoneNumberChanged,
                inputBorder: OutlineInputBorder(),
                hintText: '(100) 123-4567 8901',
                initialCountry2LetterCode: 'US',
                errorMessage: 'Wrong number',
              ),
              Container(
                padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0),
                child: Text(
                  'Custom Decoration without validation',
                  style: Theme.of(context)
                      .primaryTextTheme
                      .body1
                      .apply(fontSizeFactor: 1.5, color: Colors.black),
                ),
              ),
              InternationalPhoneNumberInput.withCustomDecoration(
                onInputChanged: onPhoneNumberChanged,
                initialCountry2LetterCode: 'US',
                inputDecoration: InputDecoration(
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.all(
                      Radius.circular(40),
                    ),
                  ),
                ),
              ),
              Container(
                padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0),
                child: Text(
                  'Custom Decoration with validation',
                  style: Theme.of(context)
                      .primaryTextTheme
                      .body1
                      .apply(fontSizeFactor: 1.5, color: Colors.black),
                ),
              ),
              InternationalPhoneNumberInput.withCustomDecoration(
                  onInputChanged: onPhoneNumberChanged,
                  onInputValidated: onInputChanged,
                  initialCountry2LetterCode: 'US',
                  inputDecoration: InputDecoration(
                    hintText: 'Enter phone number',
                    errorText: valid ? null : 'Invalid',
                    border: OutlineInputBorder(
                      borderRadius: BorderRadius.all(
                        Radius.circular(40),
                      ),
                    ),
                  )),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  intl_phone_number_input: ^0.1.0

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:intl_phone_number_input/intl_phone_number_input.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
78
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]
89
Learn more about scoring.

We analyzed this package on Oct 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
libphonenumber ^1.0.0 1.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test