SimpleCustomProperty constructor
SimpleCustomProperty(})
Class for simple custom conversions. E.g.:
final Map<String, double> conversionMap = {
'EUR': 1,
'USD': 1.2271,
'GBP': 0.9033,
'JPY': 126.25,
'CNY': 7.9315,
};
final Map<String, String> mapSymbols = {
'EUR': '€',
'USD': '\$',
'GBP': '₤',
'JPY': '¥',
'CNY': '¥',
};
var customConversion = SimpleCustomProperty(conversionMap, mapSymbols: mapSymbols);
customConversion.convert('EUR', 1);
Unit usd = customConversion.getUnit('USD');
print('1€ = ${usd.stringValue}${usd.symbol}');
Implementation
SimpleCustomProperty(this.mapConversion,
{super.significantFigures,
super.removeTrailingZeros,
super.useScientificNotation,
super.mapSymbols,
name})
: assert(mapConversion.containsValue(1),
'One conversion coefficient must be 1, this will considered the base unit'),
assert(() {
if (mapSymbols != null) {
for (var val in mapConversion.keys) {
if (!mapSymbols.keys.contains(val)) {
return false;
}
}
}
return true;
}(),
'mapSymbols should be null or containing all the keys of mapConversion'),
super(
name: name ?? 'SimpleCustomProperty',
conversionTree: _convertMapToConversionTree(mapConversion),
);