美文网首页Flutter中文社区Android开发经验谈Flutter圈子
Flutter学习中的问题记录: SnackBar弹不出怎么办

Flutter学习中的问题记录: SnackBar弹不出怎么办

作者: jzhu085 | 来源:发表于2018-07-15 10:33 被阅读51次

是不是遇到过这种问题:

image.png

原因:

[Scaffold.of], to obtain the current [ScaffoldState], which manages the
display and animation of snack bars.
[ScaffoldState.showSnackBar], which displays a [SnackBar].
[ScaffoldState.removeCurrentSnackBar], which abruptly hides the currently
displayed snack bar, if any, and allows the next to be displayed.

解决方案:

  var _scaffoldkey = new GlobalKey<ScaffoldState>();

   return new Scaffold(
      key: _scaffoldkey,
      ........
      ),
      .......
      onPressed: () {
     var snackBar = SnackBar(content: Text('显示snackBar'));
     _scaffoldkey.currentState.showSnackBar(snackBar);
              }
       .......

实战代码已经上传到我的GITHUB ZhihuDailyPurifyByFlutter

基础学习过程中的代码都放在GITHUB Flutter_Study

每天学一点,学到Flutter发布正式版!

相关文章

网友评论

    本文标题:Flutter学习中的问题记录: SnackBar弹不出怎么办

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