drawer property
A panel displayed to the side of the body, often hidden on mobile devices. Swipes in from either left-to-right (TextDirection.ltr) or right-to-left (TextDirection.rtl)
Typically a Drawer.
To open the drawer, use the ScaffoldState.openDrawer function.
To close the drawer, use Navigator.pop.
{@tool dartpad --template=stateful_widget_material} To disable the drawer edge swipe, set the Scaffold.drawerEnableOpenDragGesture to false. Then, use ScaffoldState.openDrawer to open the drawer and Navigator.pop to close it.
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
void _openDrawer() {
_scaffoldKey.currentState!.openDrawer();
}
void _closeDrawer() {
Navigator.of(context).pop();
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(title: const Text('Drawer Demo')),
body: Center(
child: ElevatedButton(
onPressed: _openDrawer,
child: const Text('Open Drawer'),
),
),
drawer: Drawer(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('This is the Drawer'),
ElevatedButton(
onPressed: _closeDrawer,
child: const Text('Close Drawer'),
),
],
),
),
),
// Disable opening the drawer with a swipe gesture.
drawerEnableOpenDragGesture: false,
);
}
{@end-tool}
Implementation
final Widget? drawer;