fromString static method

Coin fromString(
  1. String str
)

Implementation

static Coin fromString(String str) {
  final String coinRegex = r"/^(-?[0-9]+(\\.[0-9]+)?)([0-9a-zA-Z/]+)$/";
  bool m = RegExp(coinRegex).hasMatch(str);
  if (!m) {
    throw Exception("failed to parse to Coin: $str");
  }

  var amount = double.parse(str[1]);
  var denom = str[3];

  return Coin(denom, amount);
}