Complete the code to add a drawer to the Scaffold widget.
Scaffold( appBar: AppBar(title: Text('Home')), drawer: [1], body: Center(child: Text('Welcome')), )
Container or AppBar instead of Drawer.The drawer property of Scaffold expects a Drawer widget to show the side menu.
Complete the code to add a list of items inside the drawer.
Drawer( child: [1]( children: [ ListTile(title: Text('Item 1')), ListTile(title: Text('Item 2')), ], ), )
Column which does not scroll by default.Row which arranges items horizontally.Use ListView inside the drawer to allow scrolling if items overflow.
Fix the error in the code to close the drawer when an item is tapped.
ListTile( title: Text('Close Drawer'), onTap: () { Navigator.of(context).[1](); }, )
push which adds a new route instead of closing.popUntil without a proper predicate.Use Navigator.of(context).pop() to close the drawer by popping it from the navigation stack.
Fill both blanks to create a drawer header with a title and background color.
Drawer(
child: ListView(
children: [
DrawerHeader(
decoration: BoxDecoration(color: [1]),
child: Text([2], style: TextStyle(color: Colors.white, fontSize: 24)),
),
],
),
)The decoration uses Colors.blue for background color, and the header text is 'My App'.
Fill all three blanks to navigate to a new page and close the drawer on tap.
ListTile( title: Text('Go to Settings'), onTap: () { Navigator.of(context).[1](MaterialPageRoute(builder: (context) => [2]())); Navigator.of(context).[3](); }, )
pushReplacement which replaces the current page.Use push to open the new page SettingsPage(), then pop() to close the drawer.
