country_meta 1.0.0
country_meta: ^1.0.0 copied to clipboard
A Dart-only package that provides structured metadata for all countries, including ISO codes, phone codes, currencies, localized names, and flag image URLs.
π country_meta #
A Dart-only package providing metadata for countries with ISO codes, localized names, currencies, phone codes, and flag image utilities (SVG, WebP, JPEG, Emoji).
π¦ Features #
- β ISO Alpha-2, Alpha-3, and Numeric codes
- π Phone codes
- π± Currencies and symbols
- π Localized country names: English, Russian, Arabic
- π Country lookup by code or locale
- π Flag support: Emoji, SVG / WebP / JPEG (FlagCDN)
- π§ͺ Unit tests for model serialization, equality, and indexing
πΊπ³ Flag icons provided by flagpedia.net
π Usage #
π Country Lookup #
final country = CountryRepository.byAlpha2('US');
print(country?.currency); // USD
print(country?.phoneCode); // 1
π Localized Name #
final name = country?.localizedName('ru_RU');
print(name); // Π‘ΠΎΠ΅Π΄ΠΈΠ½Π΅Π½Π½ΡΠ΅ Π¨ΡΠ°ΡΡ
π Flag URL #
// Default SVG
final svg = country?.flagUrl();
// JPEG with height
final jpeg = country?.flagUrl(
format: FlagImageFormat.jpeg,
height: FlagHeight.h160,
);
// WebP with width
final webp = country?.flagUrl(
format: FlagImageFormat.webp,
width: FlagWidth.w320,
);
π Emoji Flag #
final emoji = country?.flagEmoji();
print(emoji); // πΊπΈ
β‘οΈ Direct Flag Access #
You donβt need to resolve a full CountryMeta to show a flag. Both emoji and image URLs can be generated directly from ISO alpha-2 codes.
// Emoji flags
print(FlagEmojiBuilder.build('US')); // πΊπΈ
print(FlagEmojiBuilder.build('DE')); // π©πͺ
// Flag URLs
print(FlagUrlBuilder.svg('US')); // https://flagcdn.com/us.svg
print(FlagUrlBuilder.webp('US', width: FlagWidth.w40));
print(FlagUrlBuilder.jpeg('JP', height: FlagHeight.h80));
π§ͺ Testing #
Run all tests:
dart test
Includes tests for:
- β
CountryMetamodel parsing, serialization, equality - π¦ Country repository lookup
- π Localized name fallback logic
- π Flag URL generation and format fallback