首页 > 解决方案 > 如何在颤动中更改TextField的颜色样式

问题描述

我有一个像这样的简单 TextField 小部件

TextField(
      obscureText: widget.placeholder == "Password" ? _isHidePassword : false,
      decoration: InputDecoration(
        
        hintText: "${widget.placeholder}",
        hintStyle: TextStyle(
          color: Colors.grey,
        ),
        // labelText: "${widget.placeholder}",
        // labelStyle: TextStyle(color: greenMain),
      ),
    )

它给出了如下图所示的结果: 在此处输入图像描述

有没有办法将蓝色变成另一种?喜欢红色的还是绿色的?

标签: fluttercolorsstylestextfield

解决方案


咱们试试吧

Theme(
        data: new ThemeData(
          primaryColor: Colors.redAccent,
          primaryColorDark: Colors.red,
        ),
        child: TextField(
          keyboardType: TextInputType.text,
          decoration: InputDecoration(
            
            labelText: "Text field*",
          ),
        ),
      ),

推荐阅读