Skip to content
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

RangeError was thrown while dispatching notifications for MoneyMaskedTextController #57

Open
cassioseffrin opened this issue Aug 24, 2020 · 4 comments

Comments

@cassioseffrin
Copy link

cassioseffrin commented Aug 24, 2020

I am getting this exception when the MoneyMaskedTextController is set to blank ("")

flutter --version
Flutter 1.20.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision bbfbf1770c (11 days ago) • 2020-08-13 08:33:09 -0700
Engine • revision 9d5b21729f
Tools • Dart 2.9.1

flutter_masked_text: 0.8.0

Here is the initializer
_myMoneyField = MoneyMaskedTextController(
decimalSeparator: ',',
thousandSeparator: '.',
precision: 3,
initialValue: 1);

══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞════════════════════════════════════════════════════════
The following RangeError was thrown while dispatching notifications for MoneyMaskedTextController:
Invalid value: Only valid value is 0: -2
When the exception was thrown, this was the stack:

(elided 3 frames from dart:async)
The MoneyMaskedTextController sending notification was:
MoneyMaskedTextController#6f686(TextEditingValue(text: ┤├, selection: TextSelection(baseOffset:
-1, extentOffset: -1, affinity: TextAffinity.downstream, isDirectional: false), composing:
TextRange(start: -1, end: -1)))

@denyjav
Copy link

denyjav commented Sep 25, 2020

Did you manage to solve?

@denyjav
Copy link

denyjav commented Sep 26, 2020

Eu resolvi.

O erro acima parou de ser lançado ao mudar o código fonte do widget. O método numberValue estava assim:

double get numberValue {
List parts = _getOnlyNumbers(this.text).split('').toList(growable: true);

parts.insert(parts.length - precision, '.');

return double.parse(parts.join());
}

e alterei de forma que ficasse assim:

double get numberValue => double.parse(_getSanitizedText(this.text)) / 100.0;

Foi preciso também, adicionar o método _getSanitizedText:

String _getSanitizedText(String text) {
String cleanedText = text;

var valuesToSanitize = [this.thousandSeparator, this.decimalSeparator];

valuesToSanitize.forEach((val) {
cleanedText = cleanedText.replaceAll(val, '');
});

cleanedText = _getOnlyNumbers(cleanedText);

return cleanedText;

@cassioseffrin
Copy link
Author

The error was been caused when I have changed the text of MoneyMaskedTextController to blank text.
_precoController.text = '';

I switch to:
_precoController.updateValue(0);

The error have disappeared. The downside is when I update the value "updateValue(0)" I get the mask 0,00 on the instead of blank TextField. I don't found a way to clean/reset the TextFiled with (X) suffix icon to reset my TextField.

@LampeMW
Copy link

LampeMW commented Sep 30, 2020

Following this as well, would really like a way to be able to call textController.clear() without getting this error while using the MoneyMaskedTextController.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants