Flutter TextField input only decimal numbers

后端 未结 3 1559
醉酒成梦
醉酒成梦 2021-01-05 16:56

I want to input only decimal number in TextField in Flutter. I tried below code but that\'s not working. It allows alpha (a-z) and special characte

3条回答
  •  無奈伤痛
    2021-01-05 17:35

    I am using this code and it's giving different results , on some phones it shows only numbers and on others it shows dashes and other chars , so it depends on the launcher or something like that i guess, in iPhone i guess it will show the correct keyboard ( i have tried on iPhone 7s plus).

    the inputFormatters will allow only numbers so you will get what you want.

       TextField(
         textAlign: TextAlign.start,
         keyboardType: TextInputType.numberWithOptions(decimal: true),
         inputFormatters: [
                              FilteringTextInputFormatter.digitsOnly
                           ],
       ),
    

提交回复
热议问题