EtherAmount.fromUnitAndValue constructor

EtherAmount.fromUnitAndValue(
  1. EtherUnit unit,
  2. dynamic amount
)

Constructs an amount of Ether by a unit and its amount. amount can either be a base10 string, an int, or a BigInt.

Implementation

factory EtherAmount.fromUnitAndValue(EtherUnit unit, dynamic amount) {
  BigInt parsedAmount;

  if (amount is BigInt) {
    parsedAmount = amount;
  } else if (amount is int) {
    parsedAmount = BigInt.from(amount);
  } else if (amount is String) {
    parsedAmount = BigInt.parse(amount);
  } else {
    throw ArgumentError('Invalid type, must be BigInt, string or int');
  }

  return EtherAmount.inWei(parsedAmount * _factors[unit]!);
}