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

Mau*_*mas 11 styles coding-style dart flutter

我正在使用我的应用程序的样式,我无法更改TextField输入的颜色,没有任何属性可以更改它.

 new Theme(
            data: new ThemeData(
              hintColor: Colors.white
            ),
            child:
        new TextField(
          focusNode: _focusUsername,
          controller: _controller,
          decoration: new InputDecoration(
            border: InputBorder.none,
            fillColor: Colors.grey,
            filled: true,

            hintText: 'Username',
          ))),
Run Code Online (Sandbox Code Playgroud)

Gün*_*uer 17

你可以分配一个 TextStyle

new TextField(
  style: new TextStyle(color: Colors.white),
  ...
Run Code Online (Sandbox Code Playgroud)

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


小智 11

要在我使用的 ThemeData 中更改它:

ThemeData(
      textTheme: TextTheme(subtitle1: TextStyle(color: Colors.grey)),
Run Code Online (Sandbox Code Playgroud)


Feu*_*Feu 5

在下面的示例中,文本为“红色”,文本字段的背景为“橙色”。

new TextField(
  style: new TextStyle(color: Colors.red),
  decoration: new InputDecoration(fillColor: Colors.orange, filled: true),
)
Run Code Online (Sandbox Code Playgroud)

你是这个意思吗?

如果您想通过该应用程序的主题来进行此操作,那确实很棘手。大概是这样的:

theme: new ThemeData(
    textTheme: new TextTheme(
      body1: new TextStyle(color: Colors.black),
      body2: new TextStyle(color: Colors.black),
      button: new TextStyle(color: Colors.black),
      caption: new TextStyle(color: Colors.black),
      display1: new TextStyle(color: Colors.black),
      display2: new TextStyle(color: Colors.black),
      display3: new TextStyle(color: Colors.black),
      display4: new TextStyle(color: Colors.black),
      headline: new TextStyle(color: Colors.black),
      subhead: new TextStyle(color: Colors.red), // <-- that's the one
      title: new TextStyle(color: Colors.black),
    ),
    inputDecorationTheme: new InputDecorationTheme(
      fillColor: Colors.orange,
      filled: true,
    )
)
Run Code Online (Sandbox Code Playgroud)

  • `final newTextTheme = Theme.of(context).textTheme.apply( bodyColor: Colors.white, // displayColor: Colors.pink, );` 最后用这种方式 (2认同)