user14731058
user14731058

Reputation:

handle Text input action new line in text form field

how to change TextInputAction.newLine to TextInputAction.done after Continuous two new line, i need to exit new line after selected many Continuous new line

Upvotes: 1

Views: 527

Answers (1)

Stefano Amorelli
Stefano Amorelli

Reputation: 4854

One solution would be to use a state variable in a Stateful Widget:

bool _done = false;

Listen to the edited text:

TextField(
 onChanged(s) {
   if (s.substring(s.length - 2) == "\n\n") setState(() => _done = true);
   else setState(() => _done = false);
 }
)

And change the TextInputAction accordingly:

TextField(
 onChanged(s) {
   if (s.substring(s.length - 2) == "\n\n") setState(() => _done = true);
   else setState(() => _done = false);
 },
 textInputAction: _done ? TextInputAction.done : TextInputAction.newLine
)

Upvotes: 3

Related Questions