Viewing version 3.0.0. Open the latest package page.

flutter_country_selector

3.0.0

A country picker to select a country. Merged into phone_form_field, this package now re-exports it.

Download archive

Readme

Flutter Country Selector

This package has been merged into phone_form_field.

Since 3.0.0, flutter_country_selector is a thin re-export of package:phone_form_field/country_selector.dart. The sources, the translations and the tests live in phone_form_field now, so prefer importing it directly:

// still works
import 'package:flutter_country_selector/flutter_country_selector.dart';

// preferred
import 'package:phone_form_field/country_selector.dart';

Country selector of the phone_form_field package exported in its own package.

Features

  • localization: lots of supported languages
  • semantics applied

Demo

Demo available here: https://cedvdb.github.io/flutter_country_selector/

Usage

Use CountrySelector.page if you need to show the selector inside a widget that is full screen. If you need to show the selector inside a modal of some sort, use CountrySelector.sheet instead.

Navigator.of(context).push(
  MaterialPageRoute(
    builder: (ctx) => CountrySelector.page(
      onCountrySelected: (country) => Navigator.of(context).pop(country),
    ),
  ),
)

Localization

Dynamic localization

Use CountrySelectorLocalization.of(context)?.countryName(isoCode) when you need to dynamically localize the name of a country.

Supported languages

  • ar
  • de
  • el
  • en
  • es
  • fa
  • fr
  • he
  • hi
  • hu
  • it
  • ko
  • ku
  • nb
  • nl
  • pl
  • pt
  • ro
  • ru
  • sv
  • tr
  • uk
  • ur
  • uz
  • vi
  • zh

Setup

Example setup:

import 'package:material_ui/material_ui.dart';
import 'package:phone_form_field/country_selector.dart';
import 'package:phone_form_field/phone_form_field.dart';

const MaterialApp(
  locale: Locale('en'),
  supportedLocales: [
    Locale('en'),
  ],
  localizationsDelegates: PhoneFieldLocalization.delegates,
  // ...
)

MaterialApp is material_ui's rather than the one of package:flutter/material.dart, as the widgets are built on material_ui (decoupled from the framework in Flutter 3.47.0). PhoneFieldLocalization.delegates holds material_ui's GlobalMaterialLocalizations.delegates, following the material_ui migration guide; the generated CountrySelectorLocalization.localizationsDelegates holds the flutter_localizations ones, which are a different MaterialLocalizations type and throw No MaterialLocalizations found. for non english locales.

Overwriting or adding custom flags

Some users have expressed their need to change some flags due to political reasons, or stylistic reasons. You might also wish to add your own flags. To do so refer to this issue: https://github.com/cedvdb/phone_form_field/issues/222

Development

git clone https://github.com/cedvdb/flutter_country_selector.git
cd flutter_country_selector
flutter pub get
flutter test

# the example has its own test
cd example && flutter pub get && flutter test

This package is a thin re-export, so its tests only smoke test the re-exported API against the published phone_form_field. To try out an unreleased phone_form_field change together with it, point pubspec.yaml at a sibling checkout temporarily:

dependency_overrides:
  phone_form_field:
    path: ../phone_form_field
Changelog

3.0.0

  • [Breaking] The country selector has been merged into phone_form_field. The sources, the arbs, the generated localizations and the tests now live there so that the phone field and the country selector share a single set of sources, a single l10n setup and a single dependency tree (they always shipped together). This package is now a thin re-export of package:phone_form_field/country_selector.dart: import 'package:flutter_country_selector/flutter_country_selector.dart'; keeps working, import 'package:phone_form_field/country_selector.dart'; is preferred.
  • CountrySelectorLocalization and CountrySelectorLocalizationEn are now aliases of PhoneFieldLocalizationImpl and PhoneFieldLocalizationImplEn, so .delegate, .of(context), .supportedLocales and the country names extension keep working.

2.0.4

  • Add Romanian localization
  • Added missing Japanese and Thai translations

2.0.3

  • Use deferred imports for localizations

2.0.2

  • Fix Spanish country name translations (China, Turkey, Togo, Isle of Man, Jordan, Guyana, Libya, Iran, French Polynesia and others were mistranslated or misspelled)

2.0.1

  • Bump version

2.0.0

  • [Breaking]: Require dart >=3.5.0
  • [Breaking]: Require flutter >=3.47.0
  • Migrate to the new material_ui package which has been decoupled from the flutter framework in flutter 3.47.0

1.0.19

  • Semantics fix for search field

1.0.18

  • Add Polish localization

1.0.17+1

  • Auto publish workflow implemented

1.0.17

  • Fix a memory leak in the CountrySelectorBase widget

1.0.16

  • Use theme default for AppBar elevation.

1.0.15

  • Added fix for Hebrew localization

1.0.14

  • Add Catalan

1.0.13

  • Add localizations for Urdu

1.0.12

  • Fix translation in Vietnamese
  • Add localizations for Hebrew
  • Upgrade dependency

1.0.11

  • Added localizations for vi

1.0.10

  • Added localizations for Korean

1.0.9

  • Fix translation in Portuguese

1.0.8

  • Fix translation el
  • Update readme

1.0.7

  • Fix missing localizations
  • Use newer version of circle_flags
  • Add readme note about overwriting flags

1.0.6

  • Added localizations for hu
  • Fixed fr localizations

1.0.5

  • Added missing localizations for pt and ru
  • Upgraded phone_numbers_parser

1.0.4

  • Improve accessibility

1.0.3

  • Update demo gif

1.0.2

  • Add countryDialCode method to CountrySelectorLocalization

1.0.1

  • Add demo gif

1.0.0

  • Initial release

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'flutter_country_selector:3.0.0'
pubspec.yaml
name: flutter_country_selector
description: A country picker to select a country. Merged into phone_form_field, this package now re-exports it.
version: 3.0.0
repository: https://github.com/cedvdb/flutter_country_selector
homepage: https://github.com/cedvdb/flutter_country_selector

environment:
  sdk: ">=3.5.0 <4.0.0"
  flutter: ">=3.47.0"

dependencies:
  flutter:
    sdk: flutter

  # The country selector sources, arbs and generated localizations live there.
  phone_form_field: ^12.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  material_ui: ^1.0.0
  flutter_lints: ^6.0.0

Version history

VersionPublishedArchiveSHA-256
1.0.0On demandDownloadb8ce62a8…84d5ca
1.0.1On demandDownload106f3fec…84e11a
1.0.2On demandDownloadcb9d9ba5…03e2af
1.0.3On demandDownload77685e26…dbe6c2
1.0.4On demandDownload34f85126…71eb71
1.0.5On demandDownload83f26109…a08fe6
1.0.6On demandDownloadce0c0bbd…5900ba
1.0.7On demandDownloadf32355c5…8a4128
1.0.8On demandDownload6da5b726…bb1328
1.0.9On demandDownload2f2e3e88…612a38
1.0.11On demandDownload814bddd5…c76fc9
1.0.12On demandDownloadfd50903a…fa2e38
1.0.13On demandDownload71e06142…50888a
1.0.14On demandDownload354ec391…c49814
1.0.16On demandDownloade2b2854d…271533
1.0.17On demandDownload1802744a…d7112b
1.0.17+1On demandDownload08cd36fa…c88933
1.0.18On demandDownload79b74572…6d31c1
1.0.19On demandDownload92d7ae90…fcf8f6
2.0.1On demandDownload0735d9ff…7d68c1
2.0.2On demandDownload780ad05f…cc1dd4
3.0.0Cached · Upstream SHA-256 matchedDownload6e127358…bc5f60

Dependencies

flutter { "sdk": "flutter" }

phone_form_field "^12.0.0"