-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CurrencyInputFormatter - onValueChange reports incorrect value when cursor is at the end #115
Comments
It's a bug of Flutter, I can't do anything with this. Sorry. |
i have this issue also. Can anyone find solution for this bug? |
Here's the workaround that I came up with, it's a custom class that extends class LocaleCurrencyInputFormatter extends CurrencyInputFormatter {
factory LocaleCurrencyInputFormatter({
required Locale locale,
required Function(Fixed value) onValueChange,
}) {
final parameters = getCurrencyFormatParameters(
locale: locale,
);
return LocaleCurrencyInputFormatter._(
leadingSymbol: parameters.leadingSymbol,
trailingSymbol: parameters.trailingSymbol,
mantissaLength: parameters.mantissaLength,
thousandSeparator: parameters.thousandSeparator,
onValueChange: (value) {
if (value.isNaN) return;
// workaround for issue
// https://github.com/caseyryan/flutter_multi_formatter/issues/115
final correctValue =
(value * pow(10, parameters.mantissaLength)).truncate() /
pow(10, parameters.mantissaLength);
final Fixed fixedValue = Fixed.fromNum(correctValue, scale: 2);
onValueChange(fixedValue);
},
);
}
LocaleCurrencyInputFormatter._({
super.leadingSymbol,
super.trailingSymbol,
super.mantissaLength,
super.thousandSeparator,
super.onValueChange,
});
} I use it together with my workaround for #134 like this: return TextFormField(
inputFormatters: [
// workaround for issue
// https://github.com/caseyryan/flutter_multi_formatter/issues/134
FixZeroBeforeInputFormatter(shouldReplace),
LocaleCurrencyInputFormatter(
locale: Localizations.localeOf(context),
onValueChange: (value) {
if (shouldReplace[0]) {
shouldReplace[0] = false;
value = Fixed.zero;
}
widget.onChanged(value);
},
),
FixZeroAfterInputFormatter(shouldReplace),
], |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am using CurrencyInputFormatter in the following way:
When the cursor is at the end of the input (example here:)
and I type something (for example
5
), the value in the input does not change (which is correct), but I get this message:which is clearly incorrect and inconsistent with the content of the input.
Can you please fix this issue?
The text was updated successfully, but these errors were encountered: