libphonenumber 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 92

libphonenumber #

This is a Flutter implementation of libphonenumber. It includes only a few features at the moment, and are added when more functionality is desired.

Getting Started #

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

1.0.1 (20191217) #

1.0.0 #

  • AndroidX support
  • Bump libphonenumber java dep to latest version

0.0.4 #

  • Another iOS fix, this time for getRegionInfo

0.0.3 #

  • iOS fix for parsing phone numbers

0.0.2 #

  • Fix Android package name issue

0.0.1 #

  • Initial version

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:flutter/services.dart';
import 'package:libphonenumber/libphonenumber.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final TextEditingController _textController = TextEditingController();
  bool _isValid = false;
  String _normalized = '';
  RegionInfo _regionInfo;

  @override
  void dispose() {
    _textController.dispose();
    super.dispose();
  }

  _showDetails() async {
    var s = _textController.text;

    bool isValid =
        await PhoneNumberUtil.isValidPhoneNumber(phoneNumber: s, isoCode: 'US');
    String normalizedNumber = await PhoneNumberUtil.normalizePhoneNumber(
        phoneNumber: s, isoCode: 'US');
    RegionInfo regionInfo =
        await PhoneNumberUtil.getRegionInfo(phoneNumber: s, isoCode: 'US');

    setState(() {
      _isValid = isValid;
      _normalized = normalizedNumber;
      _regionInfo = regionInfo;
    });
  }

  @override
  Widget build(BuildContext context) {
    var phoneText = Padding(
      padding: EdgeInsets.all(16.0),
      child: TextFormField(
        decoration: InputDecoration(
          hintText: "Phone Number",
        ),
        controller: _textController,
        keyboardType: TextInputType.phone,
      ),
    );

    var submitButton = MaterialButton(
      color: Colors.blueAccent,
      textColor: Colors.white,
      onPressed: _showDetails,
      child: Text('Show Details'),
    );

    var outputTexts = Column(
      children: <Widget>[
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('Is Valid?'),
            Padding(
              padding: EdgeInsets.only(left: 12.0),
              child: Text(
                _isValid ? 'YES' : 'NO',
                style: TextStyle(fontWeight: FontWeight.bold),
              ),
            ),
          ],
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('E164 Format:'),
            Padding(
              padding: EdgeInsets.only(left: 12.0),
              child: Text(
                _normalized,
                style: TextStyle(fontWeight: FontWeight.bold),
              ),
            ),
          ],
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('Region Info:'),
            Padding(
              padding: EdgeInsets.only(left: 12.0),
              child: Text(
                'Prefix=${_regionInfo?.regionPrefix}, ISO=${_regionInfo?.isoCode}, Formatted=${_regionInfo?.formattedPhoneNumber}',
                style: TextStyle(fontWeight: FontWeight.bold),
              ),
            ),
          ],
        ),
      ],
    );

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Plugin example app'),
        ),
        body: Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              phoneText,
              submitButton,
              Padding(padding: EdgeInsets.all(10.0)),
              Padding(
                padding: EdgeInsets.all(10.0),
                child: Text(
                  'Details for ${_textController.text}',
                  style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
                ),
              ),
              outputTexts,
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  libphonenumber: ^1.0.1

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:libphonenumber/libphonenumber.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
93
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

30 out of 30 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/libphonenumber.dart.

Run flutter format to format lib/libphonenumber.dart.

Maintenance issues and suggestions

Use constrained dependencies. (-20 points)

The pubspec.yaml contains 1 dependency without version constraints. Specify version ranges for the following dependencies: built_value.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
built_value any 7.0.9
flutter 0.0.0
Transitive dependencies
built_collection 4.3.2
collection 1.14.11 1.14.12
fixnum 0.10.11
matcher 0.12.6
meta 1.1.8
path 1.6.4
quiver 2.1.3
sky_engine 0.0.99
stack_trace 1.9.3
typed_data 1.1.6
vector_math 2.0.8