I have simple TextField
widget that auto expands to a new line if the string width was almost near of max screen width.
Here is the code:
TextEditingController textController = TextEditingController();
TextField(
controller: textController,
textInputAction: TextInputAction.done,
maxLines:null ,
expands: true,
maxLength: 200,
)
Question: How can I detect the new line in textController.text
?
E.g., we have the following sentence:
The universe is the greatest mystery known to the
human race
Notice that between 'the'
and 'human'
there is a new line.
I tried to output textController.text
but there was nothing found like \n
because the new line comes based on UI
rendering
.
How do I know that in code?
CodePudding user response:
i found solution
by providing globalKey
to the textField
widget and listen to the it's height state . if there was change of the height so that's mean new line occurs
CodePudding user response:
The simplest way to detect new line:
onChange: (value) {
if(value.endWith('\n')) {
//your code
}
}