参考:https://www.cnblogs.com/mingfeng002/p/11592228.html
解决方法:
class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Flutter SnackBar'), ), body: Builder( // body的最外层添加这个, builder: (BuildContext context) { return new Center( child: MaterialButton( color: Colors.blue, child: new Text('点我'), onPressed: () { Scaffold.of(context).showSnackBar(snackBar); })); }, ), ); }