如何在 flutter textformfield 中将输入文本颜色从黑色更改为白色

How to change the input text color to white from black in flutter textformfield

我的应用背景颜色是黑色。所以输入文本颜色是不可见的。所以我需要将输入文本颜色从黑色更改为白色。

Widget showPasswordInput() {
    return Padding(
      padding: const EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 0.0),
      child: new TextFormField(
        maxLines: 1,
        cursorColor: Colors.white,
        obscureText: true,
        autofocus: false,
        decoration: new InputDecoration(
          labelStyle: TextStyle(color: Colors.white),
            hintText: 'Password',
            hintStyle: TextStyle(color:Colors.white),
            icon: new Icon(
              Icons.lock,
              color: Colors.white,
            )),
        validator: (value) => value.isEmpty ? 'Password can\'t be empty' : null,
        onSaved: (value) => _password = value.trim(),
      ),
    );   
} 

TextFormField 有一个 style 属性 可以使用。

TextFormField(
   ...
   style: TextStyle(color: Colors.white),
)

要转换 TextField 的颜色,您可以用主题围绕它或修改 MaterialApp 主题。

使用 TextFormField

的 TextStyle属性
  Widget showPasswordInput() {
    return Padding(
      padding: const EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 0.0),
      child: new TextFormField(
        style: TextStyle(color: Colors.white),
        maxLines: 1,
        cursorColor: Colors.white,
        obscureText: true,
        autofocus: false,
        decoration: new InputDecoration(
            labelStyle: TextStyle(color: Colors.white),
            hintText: 'Password',
            hintStyle: TextStyle(color:Colors.white),
            icon: new Icon(
              Icons.lock,
              color: Colors.white,
            )),
        validator: (value) => value.isEmpty ? 'Password can\'t be empty' : null,
        onSaved: (value) => _password = value.trim(),
      ),
    );

  }