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.
Asked
Active
Viewed 212 times
0

marc_s
- 732,580
- 175
- 1,330
- 1,459

Bhargav Dobariya
- 43
- 6
2 Answers
1
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"),
),

Hoàng Long Nguyễn
- 141
- 3
0
You can simply return the status from sheet A while closing. Based on that open sheet B.
Example:
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),
),
);
}
},
),

Sujan Gainju
- 4,273
- 2
- 14
- 34