Professional Documents
Culture Documents
Difficulty Level :
Medium ● Last Updated :
10 Jun, 2022
Scaffold is a class in flutter which provides many widgets or we can say APIs like
will expand or occupy the whole device screen. It will occupy the available space.
Scaffold will provide a framework to implement the basic material design layout of the
application.
Object
↳ Diagnosticable
↳ Diagnosticable Tree
↳ Widget
↳ StateFul Widget
↳ Scaffold
const Scaffold({
Key key,
this.appBar,
this.body,
this.floatingActionButton,
this.floatingActionButtonLocation,
this.floatingActionButtonAnimator,
this.persistentFooterButtons,
this.drawer,
▲
this.endDrawer,
Login Register
this.bottomSheet,
this.backgroundColor,
this.resizeToAvoidBottomPadding,
this.resizeToAvoidBottomInset,
this.primary = true,
this.drawerDragStartBehavior
= DragStartBehavior.start,
this.extendBody = false,
this.drawerScrimColor,
})
appBar: It displays a horizontal bar which mainly placed at the top of the Scaffold.
appBar uses the widget AppBar which has its own proper ties like elevation, title,
brightness, etc.
Dar t
Output :
▲
Start Your Coding Journey Now! Login Register
body: It will display the main or primar y content in the Scaffold. It is below the appBar
and under the floatingActionButton. The widgets inside the body are at the lef t-
Data Structures Algorithms Interview Preparation Topic-wise Practice C++ Java Python C
corner by default.
Example :
Dar t
In this example, we have displayed the text Welcome to GeeksforGeeks!!! in the body. We
have displayed the text in the center of the page using Center widget. For styling the text,
▲
Start Your Coding Journey Now! Login Register
bottom corner by default. FloatingActionButton is an icon button that floats over the
content of the screen at a fixed place. If we scroll the page its position won’t change, it
will be fixed.
Dar t
Login Register
put the icon of the button using some preloaded icons in flutter SDK. The onPressed() is
a function that will be called when the button is pressed and the statements inside the
drawer: drawer is a slider menu or a panel which is displayed at the side of the
Scaffold. The user has to swipe lef t to right or right to lef t according to the action
defined to access the drawer menu. In the Appbar, an appropriate icon for the drawer
is set automatically at a par ticular position. The gesture to open the drawer is also set
Example :
Dar t
drawer: Drawer(
child: ListView(
children: const <Widget>[
DrawerHeader(
decoration: BoxDecoration(
color: Colors.green,
),
child: Text(
'GeeksforGeeks',
style: TextStyle(
color: Colors.green,
fontSize: 24,
▲
),
),
Start Your Coding Journey Now!
),
ListTile(
Login Register
title: Text('Item 1'),
),
ListTile(
title: Text('Item 2'),
),
],
),
),
A s a parent widget we took ListView and inside it, we divided the panel into two par ts,
Header and Menu.DrawerHeader is used to modif y the header of the panel. In header we
can display icon or details of user according to the application. We have used ListTile to
Output :
We can also add icons before the items using the proper ty leading of ListTile, inside
Example :
Dar t
ListTile(
title ▲
: Text('Item 1'),
Start Your Coding Journey Now!
leading
: Icon(Icons.people), ),
Login Register
ListTile(
title
: Text('Item 2'),
leading
: Icon(Icons.mail), ),
Output :
Scaffold. We have seen this navigationbar in most of the applications. We can add
Dar t
bottomNavigationBar: BottomNavigationBar(
currentIndex: 0,
fixedColor: Colors.green,
items: const [
BottomNavigationBarItem(
label: "Home",
icon: Icon(Icons.home),
),
BottomNavigationBarItem(
label: "Search",
icon: Icon(Icons.search), ▲
),
Start Your Coding Journey Now!
BottomNavigationBarItem(
label: "Profile",
Login Register
icon: Icon(Icons.account_circle),
),
],
onTap: (int indexOfItem) {}),
We use BottomNavigationBar widget to display the bar. For the color of active icon, we
use the fixedColor proper ty. To add items in the bar we use BottomNavigationBarItems
widget, inside which we give text and icon. For the action per formed on the tapping on
the items, we have onTap(int indexOfItem) function which works according to the index
Output :
Full code
Dar t
drawer: Drawer(
child: ListView(
children: const <Widget>[
DrawerHeader(
decoration: BoxDecoration(
color: Colors.green,
),
child: Text( ▲
'GeeksforGeeks',
Start Your Coding Journey Now!
style: TextStyle(
color: Colors.green,
Login Register
fontSize: 24,
),
),
),
ListTile(
title: Text('Item 1'),
),
ListTile(
title: Text('Item 2'),
),
],
),
),
floatingActionButton.
drawerScrimColor: used to define the color for the primar y content while a drawer is
open.
bottomSheet: This proper ty takes in a widget (final) as the object to display it at the
drawerEdgeDragWidth: This determines the area under which a swipe or a drag will
result in the opening of the drawer. And it takes in a double as the object.
determine the drag gesture will open the drawer or not, by default it is set to true.
object to determine whether the drag gesture will open the endDrawer or not.
this proper ty is always false but it must not be null. If it is set to true in the presence
added to the body and they are shif ted beneath the body.
▲
Start Your Coding Journey Now!
extendBodyBehindAppBar: This proper ty also takes in a boolean as the object. By
Login Register
default, this proper ty is always false but it must not be null. If it is set to true the
appBar instead of being on the body is extended above it and its height is added to the
body. This proper ty is used when the color of the appBar is not fully opaque.
floatingActionBotton.
set to true then the floating widgets on the scaffold resize themselves to avoid
Like 41
Previous Next
▲
Start Your Coding Journey Now! Login Register
4th of September,
Arenamon mint.
Learn More
NFT tournament
ArenaMon League
Ar ticle Contributed By :
Yashpaneliya
@Yashpaneliya
▲
Vote for difficulty
Current difficulty :
Medium
Load Comments
feedback@geeksforgeeks.org
Company Learn
About Us Algorithms
Careers Data Structures
In Media SDE Cheat Sheet
Contact Us Machine learning
Privacy Policy ▲
CS Subjects
Copyright Policy Video Tutorials
Start Your Coding Journey Now! Login
Courses
Register
News Languages
Python
Top News
Java
Technology
CPP
Work & Career
Golang
Business
C#
Finance
SQL
Lifestyle
Kotlin
Knowledge
@geeksforgeeks
, Some rights reserved