Field.currency constructor
Field.currency(})
Field.currency is a constructor that helps in managing currency fields
With separateSymbol, the symbol is drawn beside the amount in the
hint color, e.g. a grey \$ before 1,200.00, and the field's value is
the amount alone.
Implementation
Field.currency(
this.key, {
this.label,
required String currency,
String? value,
this.validator,
this.autofocus = false,
this.dummyData,
this.header,
this.footer,
this.titleStyle,
this.hidden = false,
this.readOnly,
Function(dynamic value)? onChanged,
FieldStyleTextField? style,
bool separateSymbol = false,
}) : _value = value,
style = style ?? FieldStyleTextField() {
CurrencyMeta currencyMeta = CurrencyInputMatcher.getCurrencyMeta(
"currency:$currency",
value: value ?? dummyData ?? "0",
onChanged: onChanged,
separateSymbol: separateSymbol,
);
this.style = (this.style as FieldStyleTextField).copyWith(
type: "currency",
keyboardType: const TextInputType.numberWithOptions(decimal: true),
inputFormatters: [currencyMeta.formatter],
);
if (separateSymbol) {
// The symbol sits beside the amount, in the hint color.
final FieldStyleTextField current = this.style as FieldStyleTextField;
final Widget symbol = _CurrencySymbol(
currencyMeta.symbol,
leads: currencyMeta.symbolLeads,
);
const BoxConstraints tight = BoxConstraints(minWidth: 0, minHeight: 0);
this.style = current.copyWith(
prefixIcon: currencyMeta.symbolLeads ? symbol : null,
suffixIcon: currencyMeta.symbolLeads ? null : symbol,
decoration: (current.decoration ?? const InputDecoration()).copyWith(
prefixIconConstraints: tight,
suffixIconConstraints: tight,
),
);
}
_value = currencyMeta.initialValue;
dummyData = null;
setOnChanged(onChanged);
widget = NyFormTextField.fromField(this);
}