is it possible to remove empty lines in TextField/TextFormField? After typing some input I type shift+enter to create some new empty lines, and then my controller takes all these empty lines.
is it possible to remove empty lines in TextField/TextFormField? After typing some input I type shift+enter to create some new empty lines, and then my controller takes all these empty lines.
3
Answers
Get the string from textfield. Let’s call this string
s
and then just dos.trimRight()
to automatically delete all empty spaces from the right side. Similarly you can dos.trimLeft()
to delete empty spaces from the left.There are two places you would want to deny whitespaces.
1.While Input is entered.
2.After Input is entered.
Use:
_controller.trim()
this will trim all the whitespace in the textformfieldborder: InputBorder.none,
in decoration:const InputDecoration()Try this code: