I need to make a textfield that only accepts up to 100 (as string) maximum, if they type 101 or more it should turn red, can you do this in flutter with or without an outside package?
I have no idea where to even start, is the first time i do something this kind.
2
Answers
You can use this custom widget, remember I set the
limit
to 5 for test:and use it like this:
To change the text color on the
TextField
if it exceeds 100 characters, you can do the following:Every
TextField
has astyle
property that accepts aTextStyle()
. Simply set thecolor
to red if the controller exceeds 100 characters.Here’s a complete runnable example: