How can we change appbar background color in flutter

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How can we change appbar background color in flutter



i am trying to set common theme for app so i need to change appbar color as color that indicate hexcode #0f0a1a


const MaterialColor toolbarColor = const MaterialColor(
0xFF151026, const <int, Color>0: const Color(0xFF151026));



i try this piece of code to make a custom color but fails.
How can i do this from themeData?





how it fails ? any errors ?
– Raouf Rahiche
Aug 8 at 7:05





NoSuchMethodException shown in emulator. does primarycolor need materialColor?
– Vineeth Mohan
Aug 8 at 7:19






check my Answer
– Raouf Rahiche
Aug 8 at 7:26




1 Answer
1



declare your Color like this


const PrimaryColor = const Color(0xFF151026);



and then in the MaterialApp level( will change the AppBar Color in the whole app ) change the PrimaryColor


MaterialApp


PrimaryColor


return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primaryColor: PrimaryColor,
),
home: MyApp(),
);



and if you want to change it in the Widget level just change the backgroundColor


backgroundColor


appBar: AppBar(
backgroundColor: PrimaryColor,
),






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS