如何在 TextField 中更改字符串输入的颜色?

我的工作在我的应用程序的样式,我不能改变的颜色输入的 TextField,没有任何属性来改变它。

 Theme(
data: new ThemeData(
hintColor: Colors.white
),
child:
TextField(
focusNode: _focusUsername,
controller: _controller,
decoration: InputDecoration(
border: InputBorder.none,
fillColor: Colors.grey,
filled: true,
hintText: 'Username',
))),
109127 次浏览

You can assign a TextStyle

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

https://docs.flutter.io/flutter/painting/TextStyle-class.html

In the example bellow, text is 'red' and the background of the TextField is 'orange'.

TextField(
style: TextStyle(color: Colors.red),
decoration: InputDecoration(fillColor: Colors.orange, filled: true),
)

Is that what you mean?

If you want to do it generically through the app's theme, it's indeed tricky. It's probably going to be something like that:

theme: ThemeData(
textTheme: TextTheme(
bodyText1: TextStyle(color: Colors.black),
bodyText2: TextStyle(color: Colors.black),
button: TextStyle(color: Colors.black),
caption: TextStyle(color: Colors.black),
subtitle1: TextStyle(color: Colors.red), // <-- that's the one
headline1: TextStyle(color: Colors.black),
headline2: TextStyle(color: Colors.black),
headline3: TextStyle(color: Colors.black),
headline4: TextStyle(color: Colors.black),
headline5: TextStyle(color: Colors.black),
headline6: TextStyle(color: Colors.black),
),
inputDecorationTheme: InputDecorationTheme(
fillColor: Colors.orange,
filled: true,
)
)

To change it in ThemeData I used:

ThemeData(
textTheme: TextTheme(subtitle1: TextStyle(color: Colors.grey)),