import 'package:money2/money2.dart';
class StringToMoneyDecoder implements MoneyDecoder<String> {
StringToMoneyDecoder(this._currencies) {
if (_currencies == null) {
throw ArgumentError.notNull('currencies');
/// Returns decoded `MoneyData` or throws a `FormatException`.
MoneyData decode(String encoded) {
// If `encoded` has an invalid format throws FormatException;
// Extracts currency code from `encoded`:
final currencyCode = ...;
// Tries to find information about a currency:
final currency = _currencies.find(currencyCode);
throw FormatException('Unknown currency: $currencyCode.');
// Using `currency.precision`, extracts minorUnits from `encoded`:
return MoneyData.from(minorUnits, currency);