Flutter更改文本框下划线颜色

5

我试图在文本字段失去焦点时更改下划线颜色。我不确定在哪里进行此更改,InputDecorationTheme 仅在选定时更改下划线颜色。我该如何实现这一点?

inputDecorationTheme: new InputDecorationTheme(
          labelStyle: new  TextStyle(
              color: Colors.blue[200],
          ),
          hintStyle: new TextStyle(color: Colors.grey),
        ),

我试图在文本字段未被选中/失去焦点时将其颜色更改为浅灰色。

enter image description here


2个回答

8

如果您需要实现类似的功能,请在您的Theme小部件中更改hintColor

new Theme(
          data: new ThemeData(
              //this changes the colour
              hintColor: Colors.grey,
              inputDecorationTheme: new InputDecorationTheme(
                  labelStyle: new TextStyle(color: Colors.blue))));

5
我们可以使用 InputDecoration
尝试这种方式。
 new TextFormField(
                        controller: passTextController,
                        decoration: new InputDecoration(
                            labelText: "Enter password",
                            enabledBorder: UnderlineInputBorder(
                              borderSide: BorderSide(color: Colors.grey),
                              //  when the TextFormField in unfocused 
                            ) ,
                            focusedBorder: UnderlineInputBorder(
                              borderSide: BorderSide(color: Colors.blue),
                              //  when the TextFormField in focused 
                            ) ,
                            border: UnderlineInputBorder(
                            )
                        ),
                        keyboardType: TextInputType.text,
                        obscureText: true,
                      ),

输出

在此输入图片描述


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接