What is the purpose of the scaffold widget in Flutter?
#widget#scaffold#material
Answer
Overview
is the fundamental layout structure for a Material Design app screen in Flutter. It provides a standard visual structure and implements common Material Design patterns like AppBar, Drawer, SnackBars, and FABs.textScaffold
Basic Structure
dartScaffold( appBar: AppBar( title: Text('My App'), ), body: Center(child: Text('Hello, World!')), floatingActionButton: FloatingActionButton( onPressed: () {}, child: Icon(Icons.add), ), )
All Scaffold Properties
| Property | Type | Description |
|---|---|---|
text | text | Top navigation bar |
text | text | Main content area |
text | text | FAB button |
text | enum | FAB position |
text | text | Navigation drawer (left) |
text | text | Drawer from right |
text | text | Navigation at bottom |
text | text | Persistent bottom sheet |
text | text | Background color |
text | text | Resize when keyboard appears |
text | text | Body extends behind bottom bar |
text | text | Body goes behind AppBar |
Full Example
dartScaffold( backgroundColor: Colors.grey[100], appBar: AppBar( title: Text('Dashboard'), actions: [ IconButton(icon: Icon(Icons.notifications), onPressed: () {}), ], ), drawer: Drawer( child: ListView( children: [ DrawerHeader(child: Text('Menu')), ListTile(title: Text('Home'), onTap: () {}), ListTile(title: Text('Profile'), onTap: () {}), ], ), ), body: Center(child: Text('Main Content')), bottomNavigationBar: BottomNavigationBar( items: [ BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'), BottomNavigationBarItem(icon: Icon(Icons.search), label: 'Search'), BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'), ], ), floatingActionButton: FloatingActionButton( onPressed: () {}, child: Icon(Icons.add), ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, )
Showing SnackBar
dartScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Action completed!'), action: SnackBarAction(label: 'Undo', onPressed: () {}), ), )
Key Point:
handles system UI overlaps (status bar, navigation bar), keyboard behavior, and the Material visual layer. Every screen in a Material Flutter app should typically have atextScaffoldat its root.textScaffold