decodeCurrency static method
Decodes an HWCurrency, or null when obj is absent.
Implementation
static HWCurrency? decodeCurrency(
DartObject? obj, {
String? defaultLocale,
String? resourcePrefix,
}) {
if (obj == null || obj.isNull) return null;
final typeName = obj.type?.element?.name;
switch (typeName) {
case 'HWFixedCurrency':
return HWCurrency.code(getField(obj, 'code')?.toStringValue() ?? '');
case 'HWDataCurrency':
final data = decodeDataType(
getField(obj, 'data'),
defaultLocale: defaultLocale,
resourcePrefix: resourcePrefix,
);
if (data == null) {
// coverage:ignore-start
throw GeneratorError('HWCurrency.data has no data');
// coverage:ignore-end
}
return HWDataCurrency(data);
}
throw GeneratorError('Unknown currency type: $typeName');
}