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.
CodePudding user response:
try this
toolbarTextStyle:
ThemeData.light().textTheme.headline6!.copyWith(fontFamily: 'OpenSans'),titleTextStyle: TextStyle(fontSize: 20) ,
CodePudding user response:
textTheme
→TextTheme
? This property is deprecated, please usetoolbarTextStyle
andtitleTextStyle
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,
),
),