【发布时间】:2018-10-28 10:14:16
【问题描述】:
我正在打电话
Scaffold.of(context).showSnackBar(SnackBar(
content: Text("Snack text"),
));
在脚手架的floatingActionButton 的onPressed 内。
我收到此错误
I/flutter (18613): Scaffold.of() called with a context that does not contain a Scaffold.
I/flutter (18613): No Scaffold ancestor could be found starting from the context that was passed to
....
当您在正文中调用Scaffold.of(context) 时,它指向了一个解决方案。
https://docs.flutter.io/flutter/material/Scaffold/of.html
但是如果你在 FloatingActionButton 的 onPressed 中调用它,同样的解决方案就不起作用
【问题讨论】:
-
添加定义了scaffold和FloatingActionButton的Widget的代码。
-
请贴出完整代码以便更好理解
标签: flutter