【问题标题】:Flutter set TextField cursor positionFlutter 设置 TextField 光标位置
【发布时间】:2021-07-13 10:20:16
【问题描述】:

我的应用中有一个简单的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,
                        ),

谁能帮帮我。

【问题讨论】:

  • 去掉或改成true这个参数enableInteractiveSelection: false

标签: flutter


【解决方案1】:

允许其他交互以及文本插入符号的移动

您想要做的是能够在用户与文本交互时移动文本插入符号。您已将 enableInteractiveSelection 设置为 false。

来自docs

当此值为 false 时,用户无法调整文本选择,无法复制文本,并且用户无法从剪贴板粘贴到文本字段中。

只允许移动文本插入符号

如果您想禁用剪切/复制/粘贴操作,建议您查看ToolbarOptions

【讨论】:

    猜你喜欢
    • 2021-05-22
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 2022-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多