【发布时间】:2019-08-18 08:12:08
【问题描述】:
有没有办法将SnackBar 与CupertinoPageScaffold 一起使用?
我收到以下错误:
Scaffold.of() called with a context that does not contain a Scaffold.
No Scaffold ancestor could be found starting from the context that was passed to Scaffold.of().
使用以下方法在子小部件中调用SnackBar:
final snackBar = SnackBar(
content: Text('Yay! A SnackBar!'),
action: SnackBarAction(
label: 'Undo',
onPressed: () {
// Some code to undo the change!
},
),
);
// Find the Scaffold in the Widget tree and use it to show a SnackBar!
Scaffold.of(context).showSnackBar(snackBar);
【问题讨论】:
-
您在代码层次结构中的哪里调用
showSnackBar? -
@MazinIbrahim 因为我正在调用它
onTap,如 Flutter 的示例中所示,flutter.dev/docs/cookbook/design/snackbars#1-create-a-scaffold -
@MazinIbrahim 是的,但我使用的是
CupertinoPageScaffold而不是材料Scaffold
标签: dart flutter flutter-cupertino