首页 > 解决方案 > 更改 TextField 颤动的选定文本颜色

问题描述

有什么方法可以更改Flutter 中TextField内选定的文本颜色?我尝试使用控制器本身,但没有太多可玩的属性。这是我想要的示例

在此处输入图像描述

有没有办法实现这种行为?

标签: flutteruser-interfacecolorstextfield

解决方案


使用TextSpan小部件,完美再现您的示例图像

RichText(
    text: TextSpan(
      // set the default style for the children TextSpans
      style: Theme.of(context).textTheme.body1.copyWith(fontSize: 30),
      children: [
        TextSpan(
            text: 'Hello, ',
        ),
        TextSpan(
          text: 'Wor',
          style: TextStyle(
            color: Colors.blue
          )
        ),
        TextSpan(
            text: 'ld',
        ),
      ]
    )
  )

推荐阅读