A Flutter package to handle country codes, country data, and phone number parsing/validation. This package provides easy access to country information, sorting capabilities, and a convenient widget for displaying and selecting countries.
Add country_code_helper
to your pubspec.yaml
:
Fetches the country code based on the SIM card information.
Example:
Country? initCountry = await CountryCode.initCountry();
print(initCountry); // Outputs the country information based on the SIM card.
Note: fallback is the first country in the list; hence, it can be sorted before selecting the first one as a fallback.
Fetches all country data and supports sorting based on a preferred list of country codes.
Map<String, Country> allCountries = CountryCode.countries();
print(allCountries); // Outputs a map of all countries with their data.
Countries can be sorted based on a preferred list of country codes. This ensures specific countries appear first in the list.
List<String> preferredCountries = ['US', 'CA', 'GB', 'AU'];
Map<String, Country> sortedCountries = CountryCode.countries(preferredCountries);
print(sortedCountries); // Outputs a map of countries sorted by the preferred list.
Retrieves country data using the country code.
Country? country = CountryCode.getCountryByCountryCode('US');
print(country); // Outputs the country information for the United States.
Fetches a list of countries based on region.
List<String> arabCountries = CountryCode.arabCountries;
List<String> easternEuropeanCountries = CountryCode.easternEuropeanCountries;
List<String> westernEuropeanCountries = CountryCode.westernEuropeanCountries;
List<String> stanCountries = CountryCode.stanCountries;
List<String> africanCountries = CountryCode.africanCountries;
Provides tools for parsing and validating phone numbers.
ParsedNumber parsedNumber = await PhoneNumberTools.parse('+123456789');
print(parsedNumber);
// Outputs the parsed phone number information :
// countryCode
// e164
// national
// type
// international
// nationalNumber
// regionCode
bool isValid = PhoneNumberTools.validate('+123456789');
print(isValid); // Outputs true/false based on whether the phone number is valid.
Access to flag images and a placeholder image path.
String flagImagePath = 'flags/PS.png'; // Example path to the Palestine flag.
// package: countryCodePackageName, use this in image widget to show package assets only
String placeholderImagePath = placeholderImgPath;
print(placeholderImagePath); // Outputs the path to the placeholder image.
A Flutter widget for displaying and selecting countries, with search functionality supporting Arabic words normalization.
Example usage:
CountryPickerWidget(
onSelected: (country) => Navigator.of(context).pop(country),
searchHintText: 'search...',
locale: Localizations.localeOf(context).languageCode,
//... more params
);
If you find this plugin helpful, consider supporting me: