Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the color of the default Scaffold body?

Tags:

flutter

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

like image 878
Denise Avatar asked Jun 07 '19 09:06

Denise


People also ask

What is the default background color of scaffold?

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]

What is the appbar property on scaffold?

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.

How to display the menu icon on the bottom of 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 ().

What is the use of scaffold widget?

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.


2 Answers

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.

like image 65
George Avatar answered Oct 17 '22 13:10

George


try setting the scaffoldBackgroundColor in the theme of your application

MaterialApp(
              key: key,
              title: 'Strong app,
              theme: ThemeData(
                 scaffoldBackgroundColor: Colors.red
              )
              ...
),
like image 5
Sami Kanafani Avatar answered Oct 17 '22 13:10

Sami Kanafani