I push a Dialog and put a button on it to close the dialog using Navigator.of(context).pop()
But when I press the button, the dialog does not close but the parent widget closes sequentially according to the widget tree. It seems that this only happens on iOS.
video for you to visualize
In parent widget:
showDialog<bool>(
context: context,
builder: (ct) => MyDialog(
)).then((v) {
if (v ?? false) {
myFunc();
}
});
In MyDialog:
void close() {
Navigator.of(context).pop(false);
}
rootNavigator: true
as some tutorials.showDialog<bool>(
context: context,
builder: (ct) => MyDialog(contx:xt
)).then((v) {
if (v ?? false) {
myFunc();
}
});
and pop :
void close() {
Navigator.of(contx).pop(false);
}
Things seem to be getting better but the problem sometimes comes back.
I push a Dialog and put a button on it to close the dialog using Navigator.of(context).pop()
But when I press the button, the dialog does not close but the parent widget closes sequentially according to the widget tree. It seems that this only happens on iOS.
video for you to visualize
In parent widget:
showDialog<bool>(
context: context,
builder: (ct) => MyDialog(
)).then((v) {
if (v ?? false) {
myFunc();
}
});
In MyDialog:
void close() {
Navigator.of(context).pop(false);
}
rootNavigator: true
as some tutorials.showDialog<bool>(
context: context,
builder: (ct) => MyDialog(contx:xt
)).then((v) {
if (v ?? false) {
myFunc();
}
});
and pop :
void close() {
Navigator.of(contx).pop(false);
}
Things seem to be getting better but the problem sometimes comes back.
Give this approach a try and let me know if it works for your use case.
Add
useRootNavigator : true
in showDialog
showDialog<bool>(
useRootNavigator : true,
context: context,
builder: (ct) => MyDialog(
)).then((v) {
if (v ?? false) {
myFunc();
}
});
You can try to pop dialog with the same BuildContext you opened it
Eg: using contextA to showDialog, then use Navigator.of(contextA).pop() to close it
Many BuildContext with the same name "context" may confuse usage