【发布时间】:2022-10-06 13:11:58
【问题描述】:
听起来很简单,在 Navigator.pop 进入上一页之后,通过ScaffoldMessenger 显示小吃栏的当前方法是什么,小吃栏显示在现在的当前页面(上一页)上?
听起来很简单,在 Navigator.pop 进入上一页之后,通过ScaffoldMessenger 显示小吃栏的当前方法是什么,小吃栏显示在现在的当前页面(上一页)上?
要将数据返回到第一个屏幕,请使用 Navigator.pop() 方法,然后显示snackbar
ElevatedButton(
onPressed: () {
// Close the screen and return "test!" as the result.
Navigator.of(context).pop();
ScaffoldMessenger.of(context)
..removeCurrentSnackBar()
..showSnackBar(const SnackBar(content: Text('test')));
},
child: const Text('close!'),
)
更多信息请阅读article
【讨论】:
首先使用
ScaffoldMessenger.of(context) ..hideCurrentSnackBar() ..showSnackBar(SnackBar(content: Text(message)));
稍后您可以使用
Navigator.pop();
【讨论】:
content: Text(response['message']),
backgroundColor: primaryColor,
dismissDirection: DismissDirection.up,
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
Navigator.of(context).pop()
【讨论】: