Flutter Scaffold.of() called wit
2022-08-25 本文已影响0人
一只搬运工的自我修养
添加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();