latest method
Returns a list of the latest rates.
Implementation
Future<List<Rate>> latest({required Currency from, Set<Currency>? to}) async {
Currency;
final url = this.url.replace(path: 'latest', queryParameters: {
'from': from.code,
if (to != null) 'to': to.map((currency) => currency.code).join(','),
});
try {
final response = await _withClient((client) => client.get(url));
final decoded = jsonDecode(response.body);
final ratesMap = (decoded['rates'] as Map).cast<String, num>();
final rates = ratesMap.keys
.map<Rate>(
(code) => Rate(from, Currency(code), ratesMap[code]!.toDouble()))
.toList();
_cache.addAll(rates.map((rate) => _Cache(rate)));
return rates;
} catch (e) {
rethrow;
}
}