Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

why does input cursor go to the start in textfield? flutter

TextField(
                                controller: tecTitle,
                                onChanged: (String title) {
                                  this.title = title;
                                  offset: this.title.length;
                                },

                                maxLines: 1,
                                style: TextStyle(
                                    fontSize: 32, fontWeight: FontWeight.w600),
                                decoration: InputDecoration(
                                  border: InputBorder.none,
                                  hintText: 'Title',
                                ),
                              ),
var tecTitle = TextEditingController(
            text: title,
          );

cursor

since I clicked the textfield to edit it, the cursor goes to the start. how can I fix it? Ive tried set the selection in TextEditingController, but selection isnt defined in it.

question from:https://stackoverflow.com/questions/65866692/why-does-input-cursor-go-to-the-start-in-textfield-flutter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See below code, your controller should be initialized as a below

 _editingController = new TextEditingController.fromValue(
            new TextEditingValue(
                text: title,
                selection: new TextSelection.collapsed(
                    offset: title.length)));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...