Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

flutter: custom color for App Bar with ThemeData

How can I make a custom color for App Bar with ThemeData?
accentColor is deprecated while colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.indigo)) expects type MaterialColor.

I know that I can make it this way

Scaffold(
      appBar: AppBar(
        backgroundColor: Color(0xFF0A0E21),
        title: Text('CAPTION'),
      ),

But I want to specify it in ThemeData

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Rather than overriding everything, it often makes sense to extend the parent theme. You can handle this by using the copyWith() method.

More about extending-the-parent-theme.

return MaterialApp(
  home: const T1(),
  theme: Theme.of(context).copyWith(
    appBarTheme: Theme.of(context).appBarTheme.copyWith(
          backgroundColor: const Color(0xFF0A0E21),
        ),
  ),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading