美文网首页
Flutter Scaffold.of() called wit

Flutter Scaffold.of() called wit

作者: 一只搬运工的自我修养 | 来源:发表于2022-08-25 17:08 被阅读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();
  1. 在Scaffold添加key
 @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
)}

3.用_scaffoldKey 调用Drawer

_scaffoldKey.currentState!.openEndDrawer();

相关文章

网友评论

      本文标题:Flutter Scaffold.of() called wit

      本文链接:https://www.haomeiwen.com/subject/cchzgrtx.html