I'm working on a website
made in Flutter
. I want that after some action is completed successfully, a dialog
is displayed, it closes automatically, and it goes back to the previous page. My problem is that I can't make the following error
disappear.
Error: Looking up a deactivated widget's ancestor is unsafe.
This is my code.
showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext buildContext) {
Timer(const Duration(milliseconds: 2000), () {
Navigator.of(buildContext).pop();
context.router.navigateBack();
});
return AlertDialog(
title: const Text(AppGlobals.invalidFieldsText),
content: const SingleChildScrollView(
child: Text(AppGlobals.invalidFieldsDescriptionText)),
);
},
);
If instead of closing the dialog
automatically, I use a button
to trigger, the error disappears.
showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext buildContext) {
return AlertDialog(
title: const Text(AppGlobals.invalidFieldsText),
content: const SingleChildScrollView(
child: Text(AppGlobals.invalidFieldsDescriptionText)),
actions: <Widget>[
TextButton(
child: const Text(AppGlobals.closeText),
onPressed: () {
Navigator.of(buildContext).pop();
context.navigateBack();
},
),
],
);
},
);
I tried to find the solution here, here, here, here, and here but I couldn't solve the problem. please help.