Sweet Rubens. What if we need a range, I don't want the user to input any value that exceeds a max value (example 0 - 100.0). Can I extend that and still allow the user to work with decimals? This is what I have thus far:
class CustomRangeTextInputFormatter extends TextInputFormatter { final double maxValue; CustomRangeTextInputFormatter({@required this.maxValue}); @override TextEditingValue formatEditUpdate( TextEditingValue oldValue, TextEditingValue newValue, ) { if (newValue.text == '') return TextEditingValue(); else if (int.parse(newValue.text) < 0) return TextEditingValue().copyWith(text: '0'); return int.parse(newValue.text) > maxValue ? TextEditingValue().copyWith(text: maxValue.toString()) : newValue; } }
But unfortunately it doesn't allow the user to use decimals. (Exemplo: 2.3, 10.7, 85.3, etc...) Thanks.
I think that's because you are using int.parse() instead of double.parse()
At least that did it for me
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Sweet Rubens. What if we need a range, I don't want the user to input any value that exceeds a max value (example 0 - 100.0). Can I extend that and still allow the user to work with decimals? This is what I have thus far:
But unfortunately it doesn't allow the user to use decimals. (Exemplo: 2.3, 10.7, 85.3, etc...)
Thanks.
I think that's because you are using int.parse() instead of double.parse()
At least that did it for me