helloitsme3
helloitsme3

Reputation: 307

How to add both TexTheme and DarkTheme?

Right now I have this piece of code:

return MaterialApp(
      theme: darkMode ? ThemeData.dark() : ThemeData.light(),

But I want to add also TextTheme which before I was applying like this:

return MateriaApp(
       theme: themeData)

ThemeData themeData = ThemeData(
  textTheme: TextTheme(
    bodyText1: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
    bodyText2: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
  ).apply(
    bodyColor: Colors.grey[500],
  ),
);

If someone knew how to use both of it in the same time, thank you in advance

Upvotes: 1

Views: 37

Answers (1)

ChessMax
ChessMax

Reputation: 2265

You can try something like this:

var theme = darkMode ? ThemeData.dark() : ThemeData.light();
theme = theme.copyWith(
    textTheme: TextTheme(
        bodyText1: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
        bodyText2: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
        ).apply(
        bodyColor: Colors.grey[500],
    ),
);

// ...
return MaterialApp(theme: theme);

Also, I should mention, that MaterialApp has a darkTheme argument. So you could write code like this:

return MaterialApp(theme: myLightTheme, darkTheme: myDarkTheme);

Upvotes: 2

Related Questions