首页 > 解决方案 > Flutter TextField 文本与背景覆盖光标

问题描述

我的 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),
                );

标签: fluttertextfield

解决方案


我认为在 a 中使用背景颜色的方法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,
  ),
),

推荐阅读