loadCountriesFromAsset static method

Future<List<Map<String, dynamic>>> loadCountriesFromAsset()

Returns a list of countries with their states from the asset file.

Implementation

static Future<List<Map<String, dynamic>>> loadCountriesFromAsset() async {
  try {
    final String jsonString = await rootBundle.loadString(
      'packages/country_state_selector/assets/countries_states.json',
    );

    final Map<String, dynamic> decoded = json.decode(jsonString);

    final List<dynamic> jsonList = decoded['data'];

    return jsonList.cast<Map<String, dynamic>>();
  } catch (error) {
    print("Error loading asset: $error");
    throw Exception('Error loading country data from asset: $error');
  }
}