getCountryByCurrencyCode static method

Future<List<Country>> getCountryByCurrencyCode(
  1. String currencyCode, {
  2. CountryFilter? filter,
})

Search by ISO 4217 currency code: Inr, Aud, Bmd, Usd, Eur, Gbp

Future<List<Country>> getCountryByCurrencyCode(){
 try{
   List<Country> result = await CountryProvider.getCountryByCurrencyCode("Inr")
   return result;
  } catch(error) {
   return null;
 }
}

Implementation

static Future<List<Country>> getCountryByCurrencyCode(String currencyCode,
    {CountryFilter? filter}) async {
  if (currencyCode.isNotEmpty) {
    final uri = "$_baseUrl" +
        Constants.countriesByCurrencyCode +
        currencyCode +
        filter.toFormattedUri;
    // print(uri);
    var response = await _client.get(Uri.parse(uri));

    if (response.statusCode == 200) {
      var countries = List<Country>.from(jsonDecode(response.body)
          .map((x) => x != null ? Country.fromJson(x) : null));
      return countries;
    }
    throw new Exception(
        "No country found. Please check if https://restcountries.eu is avialable.");
  } else {
    throw Exception("Currency code can not be empty");
  }
}