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. ); }), ); }
2.1m questions
2.1m answers
60 comments
57.0k users