【问题标题】:Flutter TextField text with background covers cursorFlutter TextField 文本与背景覆盖光标
【发布时间】:2020-10-13 15:38:51
【问题描述】:

我的 TextField 中的文本有背景。但是背景覆盖了光标。这个问题有解决方案吗?这可能是一个错误 - 光标不应落在文本背景的后面。下面是 TextField 的示例:

TextField(
                  autofocus: true,
                  keyboardType: TextInputType.multiline,
                  maxLines: null,
                  cursorColor: Colors.white,
                  cursorWidth: 3.0,
                  textInputAction: TextInputAction.done,
                  style: TextStyle(
                      color: Colors.black,
                      background: Paint()
                        ..strokeWidth = 30.0
                        ..color = Colors.white
                        ..style = PaintingStyle.stroke
                        ..strokeJoin = StrokeJoin.round),
                );

【问题讨论】:

    标签: flutter textfield


    【解决方案1】:

    我认为在TextField 中使用背景颜色的方法是使用装饰。
    大致如下:

    TextField(
      decoration: InputDecoration(
          fillColor: Colors.red,
          filled: true,
          border: OutlineInputBorder()),
      autofocus: true,
      keyboardType: TextInputType.multiline,
      maxLines: null,
      cursorColor: Colors.blue,
      cursorWidth: 3.0,
      textInputAction: TextInputAction.done,
      style: TextStyle(
        color: Colors.black,
      ),
    ),
    

    【讨论】:

    • 感谢您的回复。但是这个TextField并没有达到和我上面贴的TextField一样的效果。无论输入的文本是否填充 TextField,您的 TextField 都会创建一个完全填充颜色的 TextField 窗口。另一方面,在我的 TextField 中,颜色与文本耦合。例如,如果没有文本,则其后面没有颜色。或者如果只有几个字符,那么背景就在这几个字符的后面。
    • 我应该将此报告为错误吗?
    • @CyrusG 是的,明确报告这是一个错误
    猜你喜欢
    • 1970-01-01
    • 2019-03-08
    • 2017-09-24
    • 2020-06-22
    • 2021-05-22
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多