Skip to content

mustafa-707/flutter_country_code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

country_code_helper

StandWithPalestine Pub Package

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.

Installation

Add country_code_helper to your pubspec.yaml:

Features

Initialization

initCountry

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.

Country Data

countries

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.

Sorting

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.

Accessing Country Data

getCountryByCountryCode

Retrieves country data using the country code.

Country? country = CountryCode.getCountryByCountryCode('US');
print(country); // Outputs the country information for the United States.

Regions

Fetches a list of countries based on region.

arabCountries

List<String> arabCountries = CountryCode.arabCountries;

easternEuropeanCountries

List<String> easternEuropeanCountries = CountryCode.easternEuropeanCountries;

westernEuropeanCountries

List<String> westernEuropeanCountries = CountryCode.westernEuropeanCountries;

stanCountries

List<String> stanCountries = CountryCode.stanCountries;

africanCountries

List<String> africanCountries = CountryCode.africanCountries;

Phone Number Tools

Parsing and Validation

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.

Flags and Placeholders

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.

Widget Integration

CountryPickerWidget

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
);

Support

If you find this plugin helpful, consider supporting me:

Buy Me A Coffee

About

package that provide all u need to show country sheet

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages