Home > Software design >  Is there a way to change TextField text input color from theme configuration in Flutter
Is there a way to change TextField text input color from theme configuration in Flutter

Time:11-12

I know there is a way to change text input color of TextField using the style: TextStyle() property, but I want to change the text color from the ThemeData widget. Is there anyway to do that?

CodePudding user response:

Use:

style: TextStyle(color: Theme.of(context).primaryColor),

Replace primaryColor with one of many colors defined in ThemeData.

CodePudding user response:

ThemeData contains colorScheme, you can simply get the color from it.

To get primary color, it will be Theme.of(context).colorScheme.primary,.

     TextField(
            style: TextStyle(
              color: Theme.of(context).colorScheme.primary,
            ),
          ),
          TextField(
            style: TextStyle(
              color: Theme.of(context).colorScheme.error,
            ),
          ),

More about ColorScheme

  • Related