我想在从
AppBar
执行一个操作后显示一个SnackBar
。由于AppBar
无法通过builder构建,因此无法访问其Scaffold祖先。我知道我们可以使用GlobalKey
对象在需要时访问上下文,但我想知道是否有不使用GlobalKey
的解决方案。我找到了一些github问题和pull-request,但是我无法从中找到解决方案=> https://github.com/flutter/flutter/issues/4581 和 https://github.com/flutter/flutter/pull/9380
更多背景信息:
我有一个带有PopupMenuButton
的Appbar
,其中有一个项。当用户点击该项时,我使用showDialog
方法显示对话框,如果用户点击“ok”,我想显示一个SnackBar
。