Viewing version 3.0.0. Open the latest package page.
flutter_country_selector
3.0.0A country picker to select a country. Merged into phone_form_field, this package now re-exports it.
Readme
Flutter Country Selector
This package has been merged into phone_form_field.
Since 3.0.0,
flutter_country_selectoris a thin re-export ofpackage:phone_form_field/country_selector.dart. The sources, the translations and the tests live inphone_form_fieldnow, 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. CountrySelectorLocalizationandCountrySelectorLocalizationEnare now aliases ofPhoneFieldLocalizationImplandPhoneFieldLocalizationImplEn, so.delegate,.of(context),.supportedLocalesand 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
AppBarelevation.
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
countryDialCodemethod toCountrySelectorLocalization
1.0.1
- Add demo gif
1.0.0
- Initial release
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
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
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 1.0.0 | On demand | Download | b8ce62a8…84d5ca |
| 1.0.1 | On demand | Download | 106f3fec…84e11a |
| 1.0.2 | On demand | Download | cb9d9ba5…03e2af |
| 1.0.3 | On demand | Download | 77685e26…dbe6c2 |
| 1.0.4 | On demand | Download | 34f85126…71eb71 |
| 1.0.5 | On demand | Download | 83f26109…a08fe6 |
| 1.0.6 | On demand | Download | ce0c0bbd…5900ba |
| 1.0.7 | On demand | Download | f32355c5…8a4128 |
| 1.0.8 | On demand | Download | 6da5b726…bb1328 |
| 1.0.9 | On demand | Download | 2f2e3e88…612a38 |
| 1.0.11 | On demand | Download | 814bddd5…c76fc9 |
| 1.0.12 | On demand | Download | fd50903a…fa2e38 |
| 1.0.13 | On demand | Download | 71e06142…50888a |
| 1.0.14 | On demand | Download | 354ec391…c49814 |
| 1.0.16 | On demand | Download | e2b2854d…271533 |
| 1.0.17 | On demand | Download | 1802744a…d7112b |
| 1.0.17+1 | On demand | Download | 08cd36fa…c88933 |
| 1.0.18 | On demand | Download | 79b74572…6d31c1 |
| 1.0.19 | On demand | Download | 92d7ae90…fcf8f6 |
| 2.0.1 | On demand | Download | 0735d9ff…7d68c1 |
| 2.0.2 | On demand | Download | 780ad05f…cc1dd4 |
| 3.0.0 | Cached · Upstream SHA-256 matched | Download | 6e127358…bc5f60 |
Dependencies
flutter {
"sdk": "flutter"
}
phone_form_field "^12.0.0"