convertFromString static method

Future<Paisa> convertFromString({
  1. required String from,
  2. required String to,
  3. required double amount,
})

Converts the amount from the from currency to the to currency.
convertFromString accepts String currency codes eg: USD, INR, EUR etc Example:

CurrencyConvertor.convertFromString('USD', 'INR', 100) // This will convert 100 USD to INR

Implementation

static Future<Paisa> convertFromString({
  required String from,
  required String to,
  required double amount,
}) async {
  try {
    final rate = await _getConversionRate(from, to, amount);

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