【问题标题】:flutter how remove text underline on text selection (TextFormField)?flutter 如何删除文本选择(TextFormField)上的文本下划线?
【发布时间】:2023-01-22 21:18:31
【问题描述】:

有必要将光标移动到文本的末尾,但在 flutter 中,这是通过文本选择奇怪地实现的,我是这样做的

 textController.selection =
                TextSelection.collapsed(offset: textController.text.length);

可以用,但是打字的时候有下划线

可以以某种方式删除文本的下划线,我阅读了文档,但没有找到。

【问题讨论】:

  • 试试 InputDecoration.collapsed(hintText: "")

标签: flutter


【解决方案1】:

在 Flutter 中,您可以通过将 decoration 属性设置为不包含下划线的自定义 InputDecoration 来移除 TextFormField 中文本选择的文本下划线。

下面是一个示例,说明如何在 TextFormField 中的文本选择中删除文本下划线:

TextFormField(
  decoration: InputDecoration(
    border: InputBorder.none,
  ),
),

在此示例中,InputDecoration 类用于自定义 TextFormField 的外观。 InputDecoration 类的 border 属性设置为 InputBorder.none 这意味着它不会显示下划线。

您还可以使用 InputDecoration.collapsed,这将删除下划线并将 TextFormField 的高度降至最低。

TextFormField(
  decoration: InputDecoration.collapsed(hintText: "Enter text here"),
),

此外,您可以使用 enabledBorder 属性设置 TextFormField 未获得焦点时的边框,使用 focusedBorder 属性设置 TextFormField 获得焦点时的边框。

TextFormField(
  decoration: InputDecoration(
    enabledBorder: InputBorder.none,
    focusedBorder: InputBorder.none
  ),
)

通过这种方式,您可以删除 TextFormField 中文本选择的文本下划线。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 2022-11-30
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    相关资源
    最近更新 更多