I have two different flows in my project.
From Page C to Page A, I use this code , which works fine.
Navigator.popUntil(context, ModalRoute.withName(AssetMenu.ROUTE));
Main Page -> Page B -> Page C -> then back to Page A when button in Page C is clicked.
But when button in Page C is clicked, it shows black screen.
How should I handle this?
In your second use case Page A
is missing. When you invoke Navigator.popUntil()
the navigator goes up the stack of routes and pops them until it find the specified one. If the specified route is not on the stack, it will remove routes until the stack is empty. That is why you get the black screen.
If you want to turn Main Page -> Page B -> Page C
into Main Page -> Page A
you have to invoke Navigator.pushAndRemoveUntil()
where the new route is Page A
and the predicate matches the Main Page
. Alternatively use Navigator.pushNamedAndRemoveUntil()
.