oboard

oboard

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

如何用代码选中Flutter TextField中的文字?

首先,我们要在 Page 的 class 里定义一个 TextEditingController

TextEditingController _content = new TextEditingController();

然后,在 TextField 绑定 TextEditingController

TextField(controller: _content)

最后,把代码放在按钮里

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

注意了,baseOffset 是指起始位置,extentOffset 指的是末尾

这里的代码也就是选中从第 0 到第 2 个字符,效果如下

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