country_iso 1.0.0 copy "country_iso: ^1.0.0" to clipboard
country_iso: ^1.0.0 copied to clipboard

A pure Dart package for converting ISO 3166-1 alpha-2 country codes to alpha-3, numeric codes, and country names. Perfect for Flutter flag display!

example/country_iso_example.dart

import 'package:country_iso/country_iso.dart';

void main() {
  // Example usage of the CountryISO package for Flutter flag display

  print('=== Country ISO Code Converter for Flutter Flags ===\n');

  // Primary use case: Get flag codes for Flutter apps
  print('Flag codes for Flutter apps:');
  final countryCodes = ['NG', 'us', 'Ca', 'gb', 'de', 'jp'];

  for (final code in countryCodes) {
    final flagCode = CountryISO.flagCode(code);
    final name = CountryISO.name(code);

    if (flagCode != null) {
      print('$code -> $flagCode ($name) ✓');
    } else {
      print('$code -> Invalid code ✗');
    }
  }

  print('\n=== Detailed Country Information ===\n');

  // Test with Nigeria (ng)
  print('Nigeria (ng):');
  print('  Flag Code: ${CountryISO.flagCode('ng')}');
  print('  Alpha-3: ${CountryISO.alpha3('ng')}');
  print('  Numeric: ${CountryISO.numeric('ng')}');
  print('  Name: ${CountryISO.name('ng')}');
  print('  Valid: ${CountryISO.isValid('ng')}\n');

  // Test with United States (US) - case insensitive
  print('United States (US):');
  print('  Flag Code: ${CountryISO.flagCode('US')}');
  print('  Alpha-3: ${CountryISO.alpha3('US')}');
  print('  Numeric: ${CountryISO.numeric('US')}');
  print('  Name: ${CountryISO.name('US')}');
  print('  Valid: ${CountryISO.isValid('US')}\n');

  // Example Flutter usage pattern
  print('=== Flutter Usage Example ===');
  print('// In your Flutter app:');
  print('String userCountry = "NG"; // From user input or API');
  print('String? flagCode = CountryISO.flagCode(userCountry);');
  print('if (flagCode != null) {');
  print('  // Use with country_flags package:');
  print('  // CountryFlag.fromCountryCode(flagCode)');
  print('  // Or generate flag emoji: 🇳🇬');
  print('  print("Display flag for: \$flagCode");');
  print('} else {');
  print('  print("Invalid country code");');
  print('}\n');

  // Test with invalid code
  print('Invalid code test:');
  print('xx -> ${CountryISO.flagCode('xx')} (should be null)');
  print('Valid: ${CountryISO.isValid('xx')} (should be false)');
}
0
likes
160
points
358
downloads

Publisher

unverified uploader

Weekly Downloads

A pure Dart package for converting ISO 3166-1 alpha-2 country codes to alpha-3, numeric codes, and country names. Perfect for Flutter flag display!

Repository (GitHub)
View/report issues

Topics

#country #iso #flags #flutter #country-codes

Documentation

API reference

License

MIT (license)

More

Packages that depend on country_iso