Victor Sanni 7ac16a2763
Do not wait until dispose before removing replaced/popped page (#182315)
Regression was introduced in [Cleans up navigator pop and remove
logic](https://github.com/flutter/flutter/pull/175612/changes#top).

That PR moved the `onDidRemovePage` call to `_flushHistoryUpdates` in
phase `_RouteLifecycle.dispose`. But waiting until `dispose` causes
potential problems if the widget is rebuilt in a phase preceding that
(but after `pop` or `pushReplacement` has been called). So the outdated
page remains in the pages list even after it has been marked for
removal.

This is causing the page to be pushed again before it is finally
removed, causing the flicker.

## Before


https://github.com/user-attachments/assets/73dba22d-e668-4b2d-84f3-a0beb1faebab



## After


https://github.com/user-attachments/assets/6c8c6ffc-87f0-494f-bd41-7fde1f21d0e1



Fixes [[Navigation] Popping a nested route while the parent is
rebuilding causes a
flicker](https://github.com/flutter/flutter/issues/178570)
2026-02-17 20:23:52 +00:00
..