Position cursor at end of TextField when focused?

蹲街弑〆低调 提交于 2019-12-13 17:32:58

问题


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?

来源:https://stackoverflow.com/questions/55019550/position-cursor-at-end-of-textfield-when-focused

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!