Shashank Singh
Shashank Singh

Reputation: 35

Cannot apply textTheme inside AppBarTheme in flutter

I am trying to use textTheme inside AppBarTheme in flutter but when I run my application, nothing changes. Also my editor says that 'textTheme' is deprecated and shouldn't be used. This property is no longer used, please use toolbarTextStyle and titleTextStyle instead.

Here is my code snippet:

return MaterialApp(
  title: 'Flutter App',
  theme: ThemeData(
    colorScheme: ColorScheme.fromSwatch(
      primarySwatch: Colors.purple,
    ).copyWith(
      secondary: Colors.amber,
    ),
    fontFamily: 'QuickSand',
    appBarTheme: AppBarTheme(
      textTheme: ThemeData.light().textTheme.copyWith(
            headline6: const TextStyle(
              fontFamily: 'OpenSans',
              fontSize: 20,
            ),
          ),
    ),
  ),
  home: MyHomePage(),
);

I am a newbie and just started learning Flutter.

Upvotes: 3

Views: 1670

Answers (2)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63594

textThemeTextTheme? This property is deprecated, please use toolbarTextStyle and titleTextStyle instead.

Use titleTextStyle

appBarTheme: AppBarTheme(
titleTextStyle:
    Theme.of(context).appBarTheme.titleTextStyle?.copyWith(
          fontFamily: 'OpenSans',
          fontSize: 20,
        ),
),

If you like to use headline6 it is coming from textTheme.

appBarTheme: AppBarTheme(
  titleTextStyle: Theme.of(context).textTheme.headline6?.copyWith(
        fontFamily: 'OpenSans',
        fontSize: 20,
      ),
),

Upvotes: 4

safa
safa

Reputation: 37

try this

          toolbarTextStyle:
              ThemeData.light().textTheme.headline6!.copyWith(fontFamily: 'OpenSans'),titleTextStyle: TextStyle(fontSize: 20) ,

Upvotes: 0

Related Questions