0

I am using Flutter + Dart to make a mobile app. I have defined a CustomTheme class which looks like the following

class CustomTheme {
  static ThemeData lightTheme = ThemeData(
      primaryColor: Colors.red,
      colorScheme: ColorScheme.fromSwatch().copyWith(
          primary: Colors.red,
          secondary: Colors.green),
      textTheme: lightTheme.textTheme.copyWith(
          displayMedium:
              lightTheme.textTheme.displayMedium!.copyWith(color: Colors.blue)),
      useMaterial3: true,
      fontFamily: GoogleFonts.merriweather().fontFamily);
}

I am trying to change the color of my displayMedium but the color is not being applied. I am using it as follows:

Text("Hello", style: Theme.of(context).textTheme.displayMedium)

How can I get the color to apply?

Acheese
  • 61
  • 6

1 Answers1

0

Use this I hope it worked

class CustomTheme {
      static final TextStyle _displayMediumTextStyle = TextStyle(color: Colors.blue);

      static ThemeData lightTheme = ThemeData(
      primaryColor: Colors.red,
      colorScheme: ColorScheme.fromSwatch().copyWith(
      primary: Colors.red,
      secondary: Colors.green,
      ),
      textTheme: TextTheme(
      displayMedium: _displayMediumTextStyle,
      ).copyWith(
      headline4: _displayMediumTextStyle, // Example: Apply the same style to headline4
      ),
      useMaterial3: true,
      fontFamily: GoogleFonts.merriweather().fontFamily,
  );
}
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 24 '23 at 23:56