I want to open Drawer programmatically not by sliding it, how to disable that sliding functionality (touch functionality of Drawer)
Drawer
Using GlobalKey:
GlobalKey
final GlobalKey<ScaffoldState> _key = GlobalKey(); // Create a key @override Widget build(BuildContext context) { return Scaffold( key: _key, // Assign the key to Scaffold. drawer: Drawer(), floatingActionButton: FloatingActionButton( onPressed: () => _key.currentState!.openDrawer(), // <-- Opens drawer ), ); }
Using Builder:
Builder
@override Widget build(BuildContext context) { return Scaffold( drawer: Drawer(), floatingActionButton: Builder(builder: (context) { return FloatingActionButton( onPressed: () => Scaffold.of(context).openDrawer(), // <-- Opens drawer. ); }), ); }
1.4m articles
1.4m replys
5 comments
57.0k users