rateFromString static method

Future<Paisa> rateFromString(
  1. String from,
  2. String to
)

Returns the currency conversion rate for the given from and to currencies strings
Example:

CurrencyConvertor.rateFromString('USD', 'INR'); // Returns the conversion rate for USD to INR

Implementation

static Future<Paisa> rateFromString(String from, String to) async {
  try {
    final rate = await _getConversionRate(from, to, 1);

    return Paisa(
      amount: 1,
      rate: rate,
      from: Currency.values.firstWhereOrNull((e) => e.name == from)!,
      to: Currency.values.firstWhereOrNull((e) => e.name == to)!,
    );
  } catch (e) {
    rethrow;
  }
}