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.
How to close all the Modal bottom sheet in flutter
1.1k Views Asked by Bhargav Dobariya At
2
There are 2 best solutions below
0
On
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),
),
);
}
},
),
Before you go to B bottom sheet, you should call Navigator.pop
Example: