text stringlengths 1 372 |
|---|
), |
body: center( |
child: column( |
mainAxisAlignment: MainAxisAlignment.center, |
children: <widget>[ |
padding( |
padding: const EdgeInsets.all(8), |
child: ElevatedButton( |
onPressed: () { |
// close the screen and return "yep!" as the result. |
navigator.pop(context, 'yep!'); |
}, |
child: const Text('Yep!'), |
), |
), |
padding( |
padding: const EdgeInsets.all(8), |
child: ElevatedButton( |
onPressed: () { |
// close the screen and return "nope." as the result. |
navigator.pop(context, 'nope.'); |
}, |
child: const Text('Nope.'), |
), |
) |
], |
), |
), |
); |
} |
} |
<code_end> |
<topic_end> |
<topic_start> |
add a drawer to a screen |
in apps that use material design, |
there are two primary options for navigation: tabs and drawers. |
when there is insufficient space to support tabs, |
drawers provide a handy alternative. |
in flutter, use the drawer widget in combination with a |
scaffold to create a layout with a material design drawer. |
this recipe uses the following steps: |
<topic_end> |
<topic_start> |
1. create a scaffold |
to add a drawer to the app, wrap it in a scaffold widget. |
the scaffold widget provides a consistent visual structure to apps that |
follow the material design guidelines. |
it also supports special material design |
components, such as drawers, AppBars, and SnackBars. |
in this example, create a scaffold with a drawer: |
<code_start> |
scaffold( |
appBar: AppBar( |
title: const Text('AppBar without hamburger button'), |
), |
drawer: // add a drawer here in the next step. |
); |
<code_end> |
<topic_end> |
<topic_start> |
2. add a drawer |
now add a drawer to the scaffold. a drawer can be any widget, |
but it’s often best to use the drawer widget from the |
material library, |
which adheres to the material design spec. |
<code_start> |
scaffold( |
appBar: AppBar( |
title: const Text('AppBar with hamburger button'), |
), |
drawer: drawer( |
child: // populate the drawer in the next step. |
), |
); |
<code_end> |
<topic_end> |
<topic_start> |
3. populate the drawer with items |
now that you have a drawer in place, add content to it. |
for this example, use a ListView. |
while you could use a column widget, |
ListView is handy because it allows users to scroll |
through the drawer if the |
content takes more space than the screen supports. |
populate the ListView with a DrawerHeader |
and two ListTile widgets. |
for more information on working with lists, |
see the list recipes. |
<code_start> |
drawer( |
// add a ListView to the drawer. this ensures the user can scroll |
// through the options in the drawer if there isn't enough vertical |
// space to fit everything. |
child: ListView( |
// important: remove any padding from the ListView. |
padding: EdgeInsets.zero, |
children: [ |
const DrawerHeader( |
decoration: BoxDecoration( |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.