How can I change the color of an string-input in a TextField?

FlutterDart

Flutter Problem Overview


I am working in the styles of my app, i am not able to change the color of the input of the TextField, there isn't any property to change it.

 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',
          ))),

Flutter Solutions


Solution 1 - Flutter

You can assign a TextStyle

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

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

Solution 2 - Flutter

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,
    )
)

Solution 3 - Flutter

To change it in ThemeData I used:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMauricio De armasView Question on Stackoverflow
Solution 1 - FlutterGünter ZöchbauerView Answer on Stackoverflow
Solution 2 - FlutterFeuView Answer on Stackoverflow
Solution 3 - FlutterDariusz LelekView Answer on Stackoverflow