英文:
How to close all the Modal bottom sheet in flutter
问题
我正在创建我的应用中一系列的底部模态弹出窗口。当我从模态底部窗口 A 转到模态底部窗口 B 时,应关闭模态底部窗口 A,我不知道如何实现这一点,当我使用 navigator.pop
时,它导航回了底部窗口 A。
英文:
I'm creating series of modal bottom sheet in my app. When I go to A modal bottom sheet to B modal bottom sheet then A modal bottom sheet should be closed, I'm not getting how to achieve this, when I use navigator.pop
, then it's navigating to A bottom sheet.
答案1
得分: 1
在进入 B 底部表之前,应调用 Navigator.pop
示例:
InkWell(
onTap: () {
showModalBottomSheet(
context: context,
builder: (context) {
return InkWell(
onTap: () {
Navigator.of(context).pop();
showModalBottomSheet(
context: context,
builder: (context) {
return const Text("Bottom Sheet B");
});
},
child: const Text("Bottom Sheet A"));
});
},
child: const Text("Home"),
),
英文:
Before you go to B bottom sheet, you should call Navigator.pop
Example:
InkWell(
onTap: () {
showModalBottomSheet(
context: context,
builder: (context) {
return InkWell(
onTap: () {
Navigator.of(context).pop();
showModalBottomSheet(
context: context,
builder: (context) {
return const Text("Bottom Sheet B");
});
},
child: const Text("Bottom Sheet A"));
});
},
child: const Text("Home"),
),
答案2
得分: 0
你可以在关闭时从表格 A 返回状态。根据该状态打开表格 B。
示例:
InkWell(
child: Text('Press me'),
onTap: () async {
final result = await showModalBottomSheet(
context: context,
builder: (context) => InkWell(
child: Text('打开表格 B'),
onTap: () => Navigator.pop(context, true),
),
);
print(result);
if (mounted && result == true) {
showModalBottomSheet(
context: context,
builder: (context) => InkWell(
child: Text('关闭表格 B'),
onTap: () => Navigator.pop(context, true),
),
);
}
},
)
英文:
You can simply return the status from sheet A while closing. Based on that open sheet B.
Example:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
InkWell(
child: Text('Press me'),
onTap: () async {
final result = await showModalBottomSheet(
context: context,
builder: (context) => InkWell(
child: Text('Open SHeet B'),
onTap: () => Navigator.pop(context, true),
),
);
print(result);
if (mounted && result == true) {
showModalBottomSheet(
context: context,
builder: (context) => InkWell(
child: Text('CLose SHeet B'),
onTap: () => Navigator.pop(context, true),
),
);
}
},
),
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论