oboard

oboard

https://oboard.eu.org/
github
email
tg_channel
medium
twitter
bilibili
steam_profiles
follow

How to select text in a Flutter TextField using code?

First, we need to define a TextEditingController in the Page's class

TextEditingController _content = new TextEditingController();

Then, bind the TextEditingController to the TextField

TextField(controller: _content)

Finally, place the code in the button

new FlatButton( onPressed: () { _content.selection = TextSelection(baseOffset: 0, extentOffset: 2); })

Note that baseOffset refers to the starting position, and extentOffset refers to the end

The code here selects from the 0th to the 2nd character, with the following effect

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.