loadCountries method
Future<List<CountryModel> >
loadCountries({
- String assetPath = 'packages/location_picker_plus/assets/country.json',
Implementation
Future<List<CountryModel>> loadCountries({
String assetPath = 'packages/location_picker_plus/assets/country.json',
}) async {
if (_countries != null) return _countries!;
try {
final String data = await rootBundle.loadString(assetPath);
final List<dynamic> jsonList = json.decode(data);
_countries = jsonList.map((json) => CountryModel.fromJson(json)).toList();
_buildCountrySearchIndex();
return _countries!;
} catch (e) {
throw Exception('Failed to load countries: $e');
}
}