Simple question that I'm not finding an answer to--I have a TextField that's multi-line but I don't want to allow newlines in the text. E.g., if the user is typing and hits [Enter], I don't want a newline to register in the TextField. How do I do that?
I tried catching it in the onChanged event, but got weird rendering results:
onChanged: (value) {
if (value.endsWith('\n')) {
_textController.text = value.trim();
}
},
You should try using BlacklistingTextInputFormatter
in inputFormatters
.
inputFormatters: [
FilteringTextInputFormatter.deny(new RegExp(r"\n"))
],