ola_like_country_picker 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 83

Ola Like Country Picker #

A new country picker Flutter package built in Dart.

Introduction #

It is Flutter plug-n-play country picker package.

  1. Simple two lines of code. Initialize and Launch.
CountryPicker countryPicker = CountryPicker(
                                onCountrySelected:(country){
                                    print(country);
                                },
                              );
countryPicker.launch(context)

Installation #

https://pub.dev/packages/ola_like_country_picker#-installing-tab-

  1. To use the Country Picker look at the example below :

Example Usage: #

class _MyHomePageState extends State<MyHomePage> {
  CountryPicker countryPicker;
  Country country = Country.fromJson(countryCodes[0]); // select initial country 

  @override
  void initState() {
    super.initState();
    countryPicker = CountryPicker(onCountrySelected: (Country country) {
      print(country);
      setState(() {
        this.country = country;
      });
    });
  }
  
    @override
  Widget build(BuildContext context) {
    // To simply launch the country picker
    // use countryPicker.launch(context)
    // to forcefully dismiss use countryPicker.dismiss()
    // simple example could be
    return GestureDetector(
      child: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image:
                AssetImage(country.flagUri, package: 'ola_like_country_picker'),
          ),
        ),
      ),
      onTap: () {
        countryPicker.launch(context);
      },
    );

  }  
}

Output #

Parameters #

parameterdefaultrequiredtyperemark
onCountrySelectednullyesOnCountrySelectedCallbackcalled when country is selected.
showTitletruenoboolwhether to show title or not.
titleText"Select your country"noStringtext for title.
  1. To simply use country list view any where use CountryListView() and to modify attributes like flagWidth, flagHeight, countryTitle style etc use below arguments like
CountryListView(flagWidth:50, flagHeight:50 , itemTitleStyle: TextStyle(fontSize:20)); 

Example Usage: #

return MaterialApp(
  theme: ThemeData(primarySwatch: Colors.purple),
  home: Scaffold(
    appBar: AppBar(
      title: Text('Select Country'),
    ),
    body: CountryListView(),
  ),
);

Output #

Parameters #

parameterdefaultrequiredtyperemark
countryJsonListcountry_codesnoList<Map<String, String>>can be used to specify own set of sublist of countries from the variable country_codes
flagWidth25nodoublewidth of flag
flagHeight25nodoubleheight of flag
showFlagtruenoboolwhether to show flag or not
showDialCodetruenoboolwhether to show dial code or not
dialCodePrefix'+'noStringThe prefix added to the dial code for e.g +91 here prefix is '+'
itemTitleStylenullnoTextStyleUsed to change style of Country title e.g TextStyle(fontSize:30)
dialCodeStylenullnoTextStyleUsed to change style of Country's dial code e.g TextStyle(backgroundColor:Colors.green[400])
onSelectednullnoOnCountrySelectedCallbackWhen Any Country is selected what callback has to be executed e.g CountryListView(onSelected: (Country country){ print(country.toString() });
  1. To use the own version of CountryListView() with CountryPicker() use setCountryListView() method before calling launch() e.g.
    c = CountryPicker(onCountrySelected: (Country country) {
      print(country);
      setState(() {
        this.country = country;
      });
    });
    CountryListView clv = CountryListView(showFlag:false); //own version of CountryListView
    c.setCountryListView(clv);
    ...
    ...
    // Call c.launch(context) in GestureDetector() or other listeners 
    ...
    ...
    

Support #

The simplest way to show your support is by giving the project a star.

You can also support by becoming a patron on Patreon:

Patreon

Or by making a single donation by buying a coffee:

Buy Me A Coffee

[0.0.1] - 2019-10-06 #

  • Initial Release

[0.0.2] - 2019-10-06 #

Changed #

  • Ran flutter format on lib/src directory

[0.0.3] - 2019-10-06 #

  • Added example in example/
  • modified Readme.md

[0.0.4] - 2019-11-06 #

  • modified Readme.md

[0.0.5] - 2019-11-06 #

  • modified Readme.md

[0.0.5] - 2019-11-06 #

  • edited description

[0.0.6] - 2019-11-06 #

  • edited description

[0.0.7] - 2019-11-06 #

  • modified Readme.md

[0.0.8] - 2019-17-06 #

  • exported country picker file as well
  • modified README.md

[0.1.0] - 2019-19-06 #

  • added title property on country picker
  • modified README.md

[0.1.1] - 2019-23-06 #

  • removed glowing effect on OverScrolling.

[0.1.2] - 2020-16-06 #

  • removed unnecessary import that caused, Package not compatible with SDK dart
  • updated README.md

example/example.dart

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

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

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

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  CountryPicker c;
  Country country = Country.fromJson(countryCodes[94]);

  @override
  void initState() {
    super.initState();
    c = CountryPicker(onCountrySelected: (Country country) {
      print(country);
      setState(() {
        this.country = country;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image:
                AssetImage(country.flagUri, package: 'ola_like_country_picker'),
          ),
        ),
      ),
      onTap: () {
        c.launch(context);
      },
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  ola_like_country_picker: ^0.1.2

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:ola_like_country_picker/ola_like_country_picker.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
65
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 not compatible with SDK dart

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
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