2

I need to allow only one comma to be added to my inputNumber in flutter, I can't find any solution for this, can anyone help me with this?

2 Answers2

0

You can White list some text using this:-- WhitelistingTextInputFormatter(RegExp("[a-zA-Z]"))

You can Black list some text using this:-- BlacklistingTextInputFormatter(RegExp("[/\\]"))

Bharat
  • 51
  • 1
  • 7
0

A solution I found was to check the digit entered, if it already exists (",") I block it

       if ((newChar.contains(",") || newChar.contains(".")) && (oldValue.text.contains(","))) {
      return TextEditingValue(
        text: oldValue.text,
        selection: TextSelection.collapsed(offset: oldValue.text.length),
      );
    }