country_calling_code_picker 1.0.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 83

Country Calling Code Picker #

Searchable country picker widget ready to use in a dialog, bottom sheet and even in full screen!

1: Import the plugin using

 import 'package:country_calling_code_picker/picker.dart';

2: Initialize your UI using default country.

  void initCountry() async {
    final country = await getDefaultCountry(context);
    setState(() {
      _selectedCountry = country;
    });
  }

3: Use utility function showCountryPickerSheet to show a bottom sheet picker.

void _showCountryPicker() async{
    final country = await showCountryPickerSheet(context,);
    if (country != null) {
      setState(() {
        _selectedCountry = country;
      });
    }
}

4: Use utility function showCountryPickerDialog to show a dialog.

void _showCountryPicker() async{
    final country = await showCountryPickerDialog(context,);
    if (country != null) {
      setState(() {
        _selectedCountry = country;
      });
    }
}

5: CountryPickerWidget can be used for showing in a full screen.

class PickerPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Select Country'),
      ),
      body: Container(
        child: CountryPickerWidget(
          onSelected: (country) => Navigator.pop(context, country),
        ),
      ),
    );
  }
}
  1. If you just need the list of countries for making your own custom country picker, you can all getCountries() which returns list of countries.
List<Country> list = await getCountries(context);

[v1.0.7] - 04-06-2020 #

*Fixed text alignment in search field

[v1.0.6] - 03-06-2020 #

*Added function to get country by country code.

[v1.0.5] - 03-06-2020 #

*Fixed Default country null issue.

[v1.0.4] - 01-06-2020 #

*Added Utility functions: getDefaultCountry which return user's current country using its SIM country code. *Fixes and improvements.

[v1.0.3] - 31-05-2020 #

*Added fix for sim card exception

[v1.0.2] - 29-05-2020 #

*Added Utility functions: 1. showCountryPickerDialog & 2. showCountryPickerSheet *Fixes and improvements.

[v1.0.1] - 29-05-2020 #

*Added an option to add decoration for Search Box *Other improvements.

[v1.0.0] - 29-05-2020 #

*Added utility method for getting list of countries. You can try by just calling Utils.getCountries(). *Added option to set styles and flag size. *Other improvements.

[v0.0.1] - 26-05-2020 #

*Contains a basic CountryPickerWidget with search option.

example/lib/main.dart

import 'package:country_calling_code_picker/picker.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

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

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

class _MyHomePageState extends State<MyHomePage> {
  Country _selectedCountry;

  @override
  void initState() {
    initCountry();
    super.initState();
  }

  void initCountry() async {
    final country = await getDefaultCountry(context);
    setState(() {
      _selectedCountry = country;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Country Calling Code Picker'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            _selectedCountry == null
                ? Container()
                : Column(
                    children: <Widget>[
                      Image.asset(
                        _selectedCountry.flag,
                        package: countryCodePackageName,
                        width: 100,
                      ),
                      SizedBox(
                        height: 16,
                      ),
                      Text(
                        _selectedCountry == null
                            ? ''
                            : '${_selectedCountry?.callingCode ?? '+code'} ${_selectedCountry?.name ?? 'Name'} (${_selectedCountry?.countryCode ?? 'Country code'})',
                        textAlign: TextAlign.center,
                        style: TextStyle(fontSize: 24),
                      ),
                    ],
                  ),
            SizedBox(
              height: 100,
            ),
            RaisedButton(
              child: Text('Select Country using full screen'),
              color: Colors.amber,
              onPressed: _onPressed,
            ),
            RaisedButton(
              child: Text('Select Country using bottom sheet'),
              color: Colors.orange,
              onPressed: _onPressedShowBottomSheet,
            ),
            RaisedButton(
              child: Text('Select Country using dialog'),
              color: Colors.deepOrangeAccent,
              onPressed: _onPressedShowDialog,
            ),
          ],
        ),
      ),
    );
  }

  void _onPressed() async {
    final country =
        await Navigator.push(context, new MaterialPageRoute(builder: (context) {
      return PickerPage();
    }));
    if (country != null) {
      setState(() {
        _selectedCountry = country;
      });
    }
  }

  void _onPressedShowBottomSheet() async {
    final country = await showCountryPickerSheet(
      context,
    );
    if (country != null) {
      setState(() {
        _selectedCountry = country;
      });
    }
  }

  void _onPressedShowDialog() async {
    final country = await showCountryPickerDialog(
      context,
    );
    if (country != null) {
      setState(() {
        _selectedCountry = country;
      });
    }
  }
}

class PickerPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Select Country'),
      ),
      body: Container(
        child: CountryPickerWidget(
          onSelected: (country) => Navigator.pop(context, country),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  country_calling_code_picker: ^1.0.7

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:country_calling_code_picker/country.dart';
import 'package:country_calling_code_picker/country_code_picker.dart';
import 'package:country_calling_code_picker/functions.dart';
import 'package:country_calling_code_picker/picker.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
67
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]
83
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:country_calling_code_picker/country_code_picker.dart, package:country_calling_code_picker/functions.dart, package:flutter_sim_country_code/flutter_sim_country_code.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:country_calling_code_picker/country_code_picker.dart, package:country_calling_code_picker/functions.dart, package:flutter_sim_country_code/flutter_sim_country_code.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:country_calling_code_picker/country_code_picker.dart, package:country_calling_code_picker/functions.dart, package:flutter_sim_country_code/flutter_sim_country_code.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:country_calling_code_picker/country_code_picker.dart, package:country_calling_code_picker/functions.dart, package:flutter_sim_country_code/flutter_sim_country_code.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [country_calling_code_picker] that is in a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
flutter_sim_country_code ^0.0.3 0.0.3
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test