Say I have widgets ScreenA, ScreenB, and ScreenC. A has a button that takes you to B, and B has a form, which when completed, you press a button and it takes you to C.
When I’m on ScreenB, I want to be able to press the back button and go to ScreenA, which is easy. I just use Navigator.maybePop(context)
. Cool. But when I successfully make it to ScreenC, I don’t want to go back to the already completed and submitted form, I want to go back to ScreenA.
What I’m seeing so far is that when I push page C on the navigator, I should use Navigator.of(context).pushAndRemoveUntil
, but my understanding is that it wouldn’t just clear ScreenB from the navigator. It would clear ScreenA as well, and anything that came before A. My goal is simply to clear screen B.
Your help is appreciated! Thank you!
2
Answers
Figured it out after a few hours of looking through documentation, I found a pretty easy fix.
When you're done with ScreenB, instead of calling
push
, you callpushReplacement
. Here's what that looks like:Hope this is at least helpful to someone who has this issue in the future.
According to release notes
In screen C, wrap your scaffold with a
PopScope
You can use the below code :
If it’s helpful to you, then accept the answer and don’t forget to upvote.