flutter - Flutter 设置 TextField 光标位置
问题描述
我的应用程序中有一个简单的TextField
小部件。我注意到蓝色光标始终位于末尾,以便我可以在那里输入更多文本。但是,当我在输入的开头或中间的任何地方点击以更改光标焦点位置时,它不会去那里。它总是在那里,我必须删除所有输入才能回到那里。
我已经搜索了如何实现这一点,但我发现最接近的是这个我不明白的小例子。
https://www.codegrepper.com/code-examples/whatever/flutter+texteditingcontroller+cursor+position
以下是我的小部件。
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,
),
谁能帮帮我。
解决方案
允许其他交互以及文本插入符号的移动
您想要做的是能够在用户与文本交互时移动文本插入符号。您已设置enableInteractiveSelection
为假。
从文档:
如果为 false,则用户无法调整文本选择,无法复制文本,并且用户无法从剪贴板粘贴到文本字段中。
只允许移动文本插入符号
如果您想禁用剪切/复制/粘贴操作,我建议您查看ToolbarOptions。
推荐阅读
- javascript - 使用 JavaScript 换行以跨越 InnerText
- javascript - JS/Vue - 返回承诺异步问题
- python - 多个环境的 Django Cronjob 问题
- laravel - 从 Laravel 连接查询中选择同一个表中的多个列是否有更短的方法?
- laravel - laravel8 容器标签和标签不起作用
- python - 无法计算梯度下降线性回归
- google-apps-script - 使用替代运行时(NodeJS 后端)构建的 Gmail 插件有时会在插件上引发 HTTP 超时错误
- python - 旋转矩阵环第一行出错
- firebird - 如何在 Firebird 中评估数学表达式
- neo4j - 在 Neo4j 中查找从根到树中节点的路径