convert static method

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

Converts the given amount from one currency to another.
Returns Paisa object with the converted amount.

  • from is the Currency to convert from.
  • to is the Currency enum to convert to.
  • amount is the amount to convert.

Currency enum is used to specify the currency.
Returns the converted amount.

Throws ArgumentError if amount is null or less than 0.
Example:

CurrencyConvertor().convert(Currency.USD, Currency.INR, 100);

Implementation

static Future<Paisa> convert({
  required Currency from,
  required Currency to,
  required double amount,
}) async {
  try {
    final rate = await _getConversionRate(from.name, to.name, amount);

    return Paisa(amount: amount, rate: rate, from: from, to: to);
  } catch (e) {
    rethrow;
  }
}