I want to hide the first alert dialog when I call showDialog() from it. After that when I close the second dialog I want the first dialog was visible again. How I can achieve this?
Asked
Active
Viewed 620 times
1

vovaklh
- 59
- 4
-
Can you include what you;ve tried so far? – Md. Yeasin Sheikh Jul 31 '22 at 07:58
3 Answers
0
Before you call second dialog, use Navigator.of(context).pop()
to close first dialog. Then, in the second one, you have functions then((value) {...})
or whenComplete(() {...})
, inside that you can use it to re-open first dialog.
That's strange that you want to close first one, why don't you just leave it alone and let the second lies on it?

Biên Nguyễn Văn
- 11
- 3
-
I don't want to close the first dialog. I want the second dialog overlapped the first and when I close it, the first dialog will be shown again. I just have added image to my question. – vovaklh Jul 31 '22 at 12:15
0
You can create common dialog to show data. if its already showing then just update data only.

Hardik Mehta
- 2,195
- 1
- 11
- 14
0
showDialog
return a future and you can pass data from dialog. The concept is here passing some flag to open the second dialog.
onPressed: () async {
final data = await showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: ElevatedButton(
onPressed: () {
Navigator.of(context)
.pop(true); // true for to show second dialog
},
child: Text("open Second dialog"),
),
);
});
if (data == true) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text("Second dialog"),
);
});
}
},

Md. Yeasin Sheikh
- 54,221
- 7
- 29
- 56