是不是遇到过这种问题:
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);
}
.......
网友评论