Reputation: 1000
How can I limit the maximum number of characters in TextField, I use maxLength property, but user can still able to type more than maxlenght.
Here is my code:
TextField(
maxLength: 10,
inputFormatters: [
LengthLimitingTextInputFormatter(10),
],
maxLengthEnforced: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Details',
),
)
Upvotes: 0
Views: 800
Reputation: 188
There is an issue on GitHub. It's related to Gboard composing. Try to hit space and the text will be truncated to the limit.
Upvotes: 1
Reputation: 8229
Try out below code
inputFormatters: [
LengthLimitingTextInputFormatter(6), // set limit according to your requirment
]
Use this property in your textfield
Upvotes: 2