text stringlengths 1 474 |
|---|
}, |
child: const Text('Pick an option, any option!'), |
); |
} |
// A method that launches the SelectionScreen and awaits the result from |
// Navigator.pop. |
Future<void> _navigateAndDisplaySelection(BuildContext context) async { |
// Navigator.push returns a Future that completes after calling |
// Navigator.pop on the Selection Screen. |
final result = await Navigator.push( |
context, |
MaterialPageRoute(builder: (context) => const SelectionScreen()), |
); |
// When a BuildContext is used from a StatefulWidget, the mounted property |
// must be checked after an asynchronous gap. |
if (!context.mounted) return; |
// After the Selection Screen returns a result, hide any previous snackbars |
// and show the new result. |
ScaffoldMessenger.of(context) |
..removeCurrentSnackBar() |
..showSnackBar(SnackBar(content: Text('$result'))); |
} |
} |
class SelectionScreen extends StatelessWidget { |
const SelectionScreen({super.key}); |
@override |
Widget build(BuildContext context) { |
return Scaffold( |
appBar: AppBar( |
title: const Text('Pick an option'), |
), |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.