添加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();