0
0
Fluttermobile~10 mins

Drawer navigation in Flutter - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a drawer to the Scaffold widget.

Flutter
Scaffold(
  appBar: AppBar(title: Text('Home')),
  drawer: [1],
  body: Center(child: Text('Welcome')),
)
Drag options to blanks, or click blank then click option'
ADrawer()
BContainer()
CAppBar()
DListView()
Attempts:
3 left
💡 Hint
Common Mistakes
Using Container or AppBar instead of Drawer.
Forgetting to add the drawer property.
2fill in blank
medium

Complete the code to add a list of items inside the drawer.

Flutter
Drawer(
  child: [1](
    children: [
      ListTile(title: Text('Item 1')),
      ListTile(title: Text('Item 2')),
    ],
  ),
)
Drag options to blanks, or click blank then click option'
ARow
BContainer
CColumn
DListView
Attempts:
3 left
💡 Hint
Common Mistakes
Using Column which does not scroll by default.
Using Row which arranges items horizontally.
3fill in blank
hard

Fix the error in the code to close the drawer when an item is tapped.

Flutter
ListTile(
  title: Text('Close Drawer'),
  onTap: () {
    Navigator.of(context).[1]();
  },
)
Drag options to blanks, or click blank then click option'
Apop
Bpush
CpushReplacement
DpopUntil
Attempts:
3 left
💡 Hint
Common Mistakes
Using push which adds a new route instead of closing.
Using popUntil without a proper predicate.
4fill in blank
hard

Fill both blanks to create a drawer header with a title and background color.

Flutter
Drawer(
  child: ListView(
    children: [
      DrawerHeader(
        decoration: BoxDecoration(color: [1]),
        child: Text([2], style: TextStyle(color: Colors.white, fontSize: 24)),
      ),
    ],
  ),
)
Drag options to blanks, or click blank then click option'
AColors.blue
B'My App'
CColors.red
D'Header'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a color for decoration.
Using a color instead of a string for the text.
5fill in blank
hard

Fill all three blanks to navigate to a new page and close the drawer on tap.

Flutter
ListTile(
  title: Text('Go to Settings'),
  onTap: () {
    Navigator.of(context).[1](MaterialPageRoute(builder: (context) => [2]()));
    Navigator.of(context).[3]();
  },
)
Drag options to blanks, or click blank then click option'
Apush
BSettingsPage
Cpop
DpushReplacement
Attempts:
3 left
💡 Hint
Common Mistakes
Using pushReplacement which replaces the current page.
Not closing the drawer after navigation.