I have a TextField
which has a default text in it from the beginning. I want the cursor to be placed at the end of the existing text when the TextField
receives focus (possibly with the condition that the text should not have already been modified from the default text).
I've tried setting the controller.selection
which didn't work. I also tried using a FocusNode
:
focusNode: FocusNode()..addListener((){
if( !record.isCommentModified )
record.textEditingController.selection = TextSelection.collapsed(offset: record.comment.length);
})
It does work, but one side effect is that multiple textfields look like they have focus at the same time. How can I prevent this? Or even better, is there a better way of achieving what I want?