添加Drawer 抽屉效果
Scaffold.of(context).openDrawer();
报错
Another exception was thrown: Scaffold.of() called with a context that does not contain a Scaffold.
1.声明
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
- 在Scaffold添加key
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
)}
3.用_scaffoldKey 调用Drawer
_scaffoldKey.currentState!.openEndDrawer();