flutter Another exception was thrown: Scaffold.of() called with a context that does not contain a Scaffold.

参考: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);
            }));
        },
      ),
    );
  }
原文地址:https://www.cnblogs.com/lude1994/p/13585777.html