world_info_plus 1.0.0%2B3

SDKflutter
Platformandroidioswindowslinuxmacosweb

Flutter package that provides detailed information about 250 countries, including dial codes, time zones, country codes, and localized country names based on the device's locale

World Info Plus Flutter Package

pub package Score Platform GitHub stars GitHub forks GitHub issues GitHub pull requests

world_info_plus is a Flutter package that provides detailed information about 250 countries across the globe. This includes calling codes, time zones, country codes (ISO Alpha-2/Alpha-3/numeric), and more. It also supports localized country names based on the device's locale or language code, if available.

demo

Features

  • Extensive Country Data: Access up to 250 countries with details like capital, continent, currency, calling code, and time zone.
  • Localization: Automatically provides localized country names based on the user's device locale (or language fallback).
  • Easy Integration: Straightforward APIs to get all countries, retrieve device country, or fetch a specific country by its alpha2 code.
  • Optional Localization Loading: If you wish to use localizedName, just call the initializeLocalizedName() function in your main before running the app.

Quick Start

Optional: Initialize Localized Names

If you want to use the localizedName field of each country, you must initialize localized names first. This will load the appropriate JSON for the device’s locale.

import 'package:world_info_plus/world_info_plus.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // IMPORTANT: Call this to load localized country names, if you need them.
  await initializeLocalizedName();

  runApp(const MyApp());
}

Basic Usage

// Getting all countries
List<Country> countries = WorldInfoPlus.countries;
print('Total countries: ${countries.length}');

// Getting the device locale
Locale deviceLocale = WorldInfoPlus.deviceLocale;
print('Device Locale: ${deviceLocale.toString()}');

// Getting the device country (based on device locale)
Country? deviceCountry = WorldInfoPlus.deviceCountry;
print('Device Country: ${deviceCountry?.name ?? "Unknown"}');

// Fetching a specific country by alpha2 code (e.g., "US", "KR", "FR")
Country? countryUS = WorldInfoPlus.getCountryByAlpha2('US');
print('Country Name: ${countryUS?.name}');
print('Country Localized Name: ${countryUS?.localizedName ?? "N/A"}');

Public API

The world_info_plus library provides a set of static methods and properties through the WorldInfoPlus class:

APIReturn TypeDescription
WorldInfoPlus.countriesList<Country>Returns a list of all available countries.
WorldInfoPlus.deviceLocaleLocaleThe current device locale derived from WidgetsBinding.instance.platformDispatcher.locale.
WorldInfoPlus.deviceCountryCountry?Attempts to match the device's locale country code to a Country. Returns null if not found.
WorldInfoPlus.getCountryByAlpha2(String alpha2)Country?Fetches a Country by its ISO Alpha-2 code (e.g., "US", "FR"). Returns null if not found.
initializeLocalizedName()Future<void>Loads localized country names based on the device’s locale. Must be called before accessing localizedName. It is recommended to call this function in the main function before running the app.

Country Model

Each country is represented by the Country class, containing the following fields:

PropertyTypeDescription
nameStringOfficial English name of the country (e.g., "United States of America").
shortNameStringA shorter or common English name (e.g., "USA").
nativeNameStringNative name of the country in its primary local language.
capitalStringName of the country’s capital city.
continentStringName of the continent (e.g., "North America", "Asia").
currencyStringThe official currency code (e.g., "Dollar", "Euro").
callingCodeStringCountry calling code (e.g., "1" for the USA, "82" for South Korea).
timeZoneInCapitalStringThe primary time zone of the capital city (e.g., "Asia/Seoul").
alpha2StringISO Alpha-2 country code (e.g., "US", "KR").
alpha3StringISO Alpha-3 country code (e.g., "USA", "KOR").
numericStringISO numeric country code (e.g., "840" for the USA).
tldStringCountry’s top-level domain (e.g., "us", "kr").
fipsStringFederal Information Processing Standards code.
localizedNameString?Localized name if initializeLocalizedName() was called; otherwise null.
extraMap<String, dynamic>?Additional information if available.
imagePathStringPath to the country’s flag image, e.g., "packages/world_info_plus/assets/flags/us.png".

Example usage of Country:

final country = WorldInfoPlus.getCountryByAlpha2('US');
if (country != null) {
  print('Name: ${country.name}');
  print('Short Name: ${country.shortName}');
  print('Localized Name: ${country.localizedName ?? "No localized name loaded"}');
  print('Capital: ${country.capital}');
  print('Continent: ${country.continent}');
  print('Currency: ${country.currency}');
  print('Calling Code: +${country.callingCode}');
  print('TimeZone: ${country.timeZoneInCapital}');
  print('Alpha2/Alpha3: ${country.alpha2} / ${country.alpha3}');
  print('Numeric: ${country.numeric}');
  print('TLD: ${country.tld}');
  print('FIPS: ${country.fips}');
  print('Image Path: ${country.imagePath}');
  print('Extra Info: ${country.extra}');
}

Contributions

Contributions are welcome! Please open issues and pull requests to improve this package.