Does onPopInvokedWithResult intercept a pop?

  • Yes, and no. It’s important to understand the sequence of events.
  • PopScope does not stop the navigation attempt before the callback runs.
  • It registers intent, controls whether the underlying route manager allows the pop, and then the callback (onPopInvokedWithResult) fires after that decision has been made.

Here is the flow chart:

canPop: true (Default)canPop: false (Block Navigation)
1. User ActionSystem back gesture or Navigator.pop() is called.System back gesture or Navigator.pop() is called.
2. Route DecisionThe route layer allows the pop to proceed.The route layer blocks the pop.
3. Callback FiresonPopInvokedWithResult is called with didPop: true.onPopInvokedWithResult is called with didPop: false.
4. ResultThe screen disappears immediately.The screen stays put. (You must manually call Navigator.pop() later if you want to dismiss it after a confirmation dialog).

Problem Scenario (using canPop: false)

  1. User clicks your “Close Modal” TextButton.
  2. The TextButton calls Navigator.of(context).pop(). This initiates a pop attempt.
  3. The PopScope sees canPop: false, so the underlying Navigator ignores the pop attempt initiated by the button.
  4. The onPopInvokedWithResult is fired with didPop: false.
  5. Inside your onPopInvokedWithResult callback, you likely have code that calls Navigator.of(context).pop() again, probably inside a confirmation dialog (as shown in my previous example).
  6. This sequence might cause unexpected behavior if your manual button pop and the PopScope logic collide awkwardly in the modal’s lifecycle, potentially processing two separate requests across different navigators if one of your contexts was subtly wrong.