2

I am curently learning Flutter on the Maximilian Udemy Course, and when I reached the section when I have to use the textTheme property of the AppBarTheme class, it's telling me that it's deprecated. What should I replace it with. Here is what im trying to do:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Personal Expenses',
      theme: ThemeData(
        primarySwatch: Colors.purple,
        accentColor: Colors.amber,
        fontFamily: 'Quicksand',
        appBarTheme: AppBarTheme(
          textTheme: ThemeData.light().textTheme.copyWith(
                headline6: TextStyle(
                  fontFamily: 'OpenSans',
                  fontSize: 20,
                ),
              ),
        ),
      ),
      home: MyHomePage(),
    );
  }
}
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
Mikelenjilo
  • 171
  • 1
  • 12

2 Answers2

3

Use colorScheme instead of accentColor and titleTextStyle and toolbarTextStyle instead of textTheme

   colorScheme: Theme.of(context).colorScheme.copyWith(
              secondary: Colors.amber,
            ),
theme: ThemeData(
  primarySwatch: Colors.purple,
  colorScheme: Theme.of(context).colorScheme.copyWith(
        secondary: Colors.amber,
      ),
  fontFamily: 'Quicksand',
  appBarTheme: AppBarTheme(
    titleTextStyle: TextStyle(),
    toolbarTextStyle: TextStyle(),
  ),
),
home: MyHomePage(),

More about using themes

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
1

The new flutter version has a built-in property called tiltleTextStyle, which targets the title of the appbar.

This method is more convenient:

appBarTheme: AppBarTheme(
          titleTextStyle: TextStyle(
            fontFamily: 'OpenSans',
            fontSize: 20,
            fontWeight: FontWeight.bold,
          ),
        ),
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83