关于dart:Flutter更改文本字段下划线颜色

Flutter change textfield underline Color

当文本框处于非活动状态/未聚焦时,我正在尝试更改其下划线颜色。 我不确定要在哪里进行更改,InputDecorationTheme仅在选择时更改下划线颜色。 我该如何实现?

1
2
3
4
5
6
inputDecorationTheme: new InputDecorationTheme(
          labelStyle: new  TextStyle(
              color: Colors.blue[200],
          ),
          hintStyle: new TextStyle(color: Colors.grey),
        ),

我试图在未选中/焦点不清晰时将文本字段的颜色更改为浅灰色。

enter image description here


对于可能需要实现类似功能的用户,请在您的Theme小部件中更改hintColor

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

我们可以使用InputDecoration

试试这个

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 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,
                      ),

输出值

enter image description here