TextInputType.numberWithOptions(decimal: true),
I'm using the above code as a keyboardType
in my TextFormField
but in some devices, the device doesn't display comma or dot. Screenshot is given below:
Thinking of using this package: https://pub.dev/packages/virtual_keyboard
Any idea on how to solve it?
This doesn't solve my problem because in my case, it's happening on Android. Flutter TextField with number keyboard, comma is needed instead of period (Only iOS)
This parameter will solve the problem
keyboardType: TextInputType.numberWithOptions(decimal: true),
It's a well known Android issue in Samsung Keyboards
https://github.com/flutter/flutter/issues/61175
Usually the work-around is to fallback to text keyboard.
I developed a package with this work-around to easy get the keyboard vendor name and then make some crafty if samsung then TextInputType.text
package: keyboard_name
However, it don't solves the problem.
First: Format Inputters
note: I didn't find a way to enable the comma
Convert the inputted dot to comma and don't worry about the disabled comma
To do this you need to extend a Text Input Formatter
class CommaFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue,
TextEditingValue newValue,
) {
String _text = newValue.text;
//This is only if you need signed numbers. Will convert the first '.'(dot) to '-'(minus)
//if (_text.isNotEmpty && _text[0] == '.')
// _text = _text.replaceFirst('.', '-');
return newValue.copyWith(
text: _text.replaceAll('.', ','),
);
}
}
Also, you can put another smartass regex to format after this one
TextFormField(
inputFormatters: [
CommaFormatter(),
FilteringTextInputFormatter.allow(
RegExp(
//r'^[-]{0,1}[0-9]*[,]?[0-9]*', //signed regex
r'^[0-9]*[,]?[0-9]*',
),
),
],
/.../
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With