Flutter – How to limit keyboard to allow digits only

This post is just my quick note on how to limit the soft keyboard to allow only digits.

Please note that on iOS, we just need to use keyboardType: TextInputType.number

However on Android, we need to set inputFormatters. The keyboard on Android still shows the dot ( . ) and hyphen ( – ), but we can not add them to the text field.

TextField(
  inputFormatters: [
    FilteringTextInputFormatter.digitsOnly,
  ],
  keyboardType: TextInputType.number,
),
Tagged : / / /
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x