rateFromCountryCode static method
Returns the currency conversion rate for the given from
and to
country codes.
Example:
CurrencyConvertor.rateFromCountryCode(from:'US', to:'IN');
Implementation
static Future<Paisa> rateFromCountryCode({
required String from,
required String to,
}) async {
final ccFrom = CountryCode.values.fromCode(from);
final ccTo = CountryCode.values.fromCode(to);
if (ccFrom == null || ccTo == null) {
throw Exception('Country code not found');
}
try {
final rate = await _getConversionRate(ccFrom.currency.name, ccTo.currency.name, 1);
return Paisa(
amount: 1,
rate: rate,
from: ccFrom.currency,
to: ccTo.currency,
);
} catch (e) {
rethrow;
}
}