Code Monkey home page Code Monkey logo

flutter_country_picker's Introduction

Country picker

pub package

A flutter package to select a country from a list of countries.

n1

Getting Started

Add the package to your pubspec.yaml:

country_picker: ^2.0.26

In your dart file, import the library:

import 'package:country_picker/country_picker.dart';

Show country picker using showCountryPicker:

showCountryPicker(
  context: context,
  showPhoneCode: true, // optional. Shows phone code before the country name.
  onSelect: (Country country) {
    print('Select country: ${country.displayName}');
  },
);

For localization:

Add the CountryLocalizations.delegate in the list of your app delegates.

MaterialApp(
      supportedLocales: [
        const Locale('en'),
        const Locale('el'),
        const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'), // Generic Simplified Chinese 'zh_Hans'
        const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'), // Generic traditional Chinese 'zh_Hant'
      ],
      localizationsDelegates: [
        CountryLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      home: HomePage(),
 );

Parameters:

  • onSelect: Called when a country is selected. The country picker passes the new value to the callback (required)
  • onClosed: Called when CountryPicker is dismissed, whether a country is selected or not (optional).
  • showPhoneCode: Can be used to show phone code before the country name.
  • searchAutofocus Can be used to initially expand virtual keyboard
  • showSearch Can be used to show/hide the search bar.
  • showWorldWide An optional argument for showing "World Wide" option at the beginning of the list
  • favorite Can be used to show the favorite countries at the top of the list (optional).
  • moveAlongWithKeyboard Can be used to move bottomSheet along with keyboard when textfield is focused (optional).
  • countryListTheme: Can be used to customize the country list's bottom sheet and widgets that lie within it. (optional).
    showCountryPicker(
      context: context,
      countryListTheme: CountryListThemeData(
        flagSize: 25,
        backgroundColor: Colors.white,
        textStyle: TextStyle(fontSize: 16, color: Colors.blueGrey),
        bottomSheetHeight: 500, // Optional. Country list modal height
        //Optional. Sets the border radius for the bottomsheet.
          borderRadius: BorderRadius.only(
          topLeft: Radius.circular(20.0),
          topRight: Radius.circular(20.0),
        ),
        //Optional. Styles the search field.
        inputDecoration: InputDecoration(
          labelText: 'Search',
          hintText: 'Start typing to search',
          prefixIcon: const Icon(Icons.search),
          border: OutlineInputBorder(
            borderSide: BorderSide(
              color: const Color(0xFF8C98A8).withOpacity(0.2),
            ),
          ),
        ),
      ),
      onSelect: (Country country) => print('Select country: ${country.displayName}'),
    );
  • exclude: Can be used to exclude(remove) one or more country from the countries list (optional).
    showCountryPicker(
      context: context,
      exclude: <String>['KN', 'MF'], //It takes a list of country code(iso2).
      onSelect: (Country country) => print('Select country: ${country.displayName}'),
    );
  • countryFilter: Can be used to filter the countries list (optional).
    • It takes a list of country code(iso2).
    • Can't provide both exclude and countryFilter

Contributions

Contributions of any kind are more than welcome! Feel free to fork and improve country_code_picker in any way you want, make a pull request, or open an issue.

flutter_country_picker's People

Contributors

daniel-ioannou avatar zamorite avatar zuhwa avatar tverra avatar kuyucuburak avatar sabreys avatar erturks avatar miguel-a-jara avatar ed-mota-teixeira avatar jsenart avatar princegupta1999 avatar adnanjpg avatar codenashwan avatar sachin-dahal avatar yuzurihaaa avatar jjchiw avatar alegos27 avatar tsinis avatar tierecke avatar linsvensson avatar cbachiller avatar rammaarf avatar mobisofts avatar wxxedu avatar uytb avatar treuova avatar sungurcihan avatar oandreyev avatar mark-taeyoung avatar kanybekmomukeyev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.