Flutter 当BuildContext在Scaffold之前时,调用Scaffold.of(context)会报错
作者:互联网
当BuildContext在Scaffold之前时,调用Scaffold.of(context)会报错。这时可以通过Builder Widget来解决,代码如下:
body: new Builder(builder: (BuildContext context) {
return new Center(
child: new GestureDetector(
onTap: () {
final snackBar =
new SnackBar(content: new Text('这是一个SnackBar'));
Scaffold.of(context).showSnackBar(snackBar);
},
child: new Text('显示SnackBar'),
),
);
})
标签:SnackBar,Scaffold,BuildContext,报错,context,new 来源: https://blog.csdn.net/qq_27981847/article/details/88310706