user12051965
user12051965

Reputation: 147

Flutter set TextField cursor position

I have a simple TextField widget in my app. I noticed that the blue cursor is always at the end so that I can input more text there. However, when I tap at the beginning of my input or anywhere in the middle in order to change cursor focus position, it does not go there. It always stays there and I have to delete all input to get back there.

enter image description here

I have searched how to achieve this but closest I found is this small example which I do not understand.

https://www.codegrepper.com/code-examples/whatever/flutter+texteditingcontroller+cursor+position

The following is my widget.

TextField(
                          controller: _descriptionTextController,
                          enableInteractiveSelection: false,
                          keyboardType: TextInputType.multiline,
                          maxLines: null,
                          decoration: InputDecoration(
                            fillColor: Colors.transparent,
                            border: InputBorder.none,
                            focusedBorder: InputBorder.none,
                            enabledBorder: InputBorder.none,
                            errorBorder: InputBorder.none,
                            disabledBorder: InputBorder.none,
                            hintText: 'Product description',
                          ),
                          style: TextFieldStyle,
                        ),

Could anyone help me please.

Upvotes: 0

Views: 1060

Answers (1)

abdev
abdev

Reputation: 617

Allowing other interactions along with movement of text caret

What you want to do is to be able to move the text caret when user interacts with the text. You have set enableInteractiveSelection to false.

From the docs:

When this is false, the text selection cannot be adjusted by the user, text cannot be copied, and the user cannot paste into the text field from the clipboard.

Allowing just the movement of text caret

In case you want to disable cut/copy/paste actions, I suggest you look into ToolbarOptions.

Upvotes: 3

Related Questions