I want to create a AppBar which has the same color as that of the Scaffold body however I am not able to figure out the color of the body. I checked the source code of Scaffold however they don't have the Color code there either.
Is there any way I can find this out? Thanks
I found the default background color of scaffold comes from backgroundColor which comes from ThemeData.scaffoldBackgroundColor If we don't define scaffoldBackgroundColor it comes from canvasColor canvasColor ??= isDark ? Colors.grey [850]! : Colors.grey [50]!; Therefore, the default color of scaffoldBackgroundColor is Colors.grey [50]
The app bar is one of the main components in your app, without it, your app may seem incomplete. The appBar widget has its own properties like elevation, title, actions, etc. This property on Scaffold is used to change the background color of the Scaffold screen. This is the main content property on Scaffold.
When you add a drawer to Scaffold, the menu icon will appear on appBar. This component is similar to appBar which is displayed at bottom of the screen. You can pass BottomNavigationBar () widget or BottomAppBar () widget on this property. You can also set notched shape on bottomNavigationBar with BottomAppBar ().
The Scaffold widget is the base of the screen for a single page. It is used to implement the basic functional layout structure of an app. You can easily implement functional widgets like AppBar, FloatingActionButton, ButtonNavigationBar, Drawer, and many more widgets on the app using the Scaffold widget.
Scaffold
gets its color from applied theme - usually the default one, if you have not overridden it.
To replicate that behaviour use:
Container(
color: Theme.of(context).scaffoldBackgroundColor
)
If you don't have access to current context
- simply use Colors.grey[50]
, which is the default canvas color in the Light theme.
try setting the scaffoldBackgroundColor
in the theme of your application
MaterialApp(
key: key,
title: 'Strong app,
theme: ThemeData(
scaffoldBackgroundColor: Colors.red
)
...
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With