flutterflutter-navigationflutter-go-router

prevent dialog from being above later pushed page


I am using typed routes with go_router in flutter.

I show a loading spinner like this:

showDialog<void>(
  context: context,
  barrierDismissible: false,
  builder: (BuildContext context) {
    return const Dialog(
      backgroundColor: Colors.transparent,
      elevation: 0,
      child: Center(
        child: CircularProgressIndicator(
          valueColor: AlwaysStoppedAnimation<Color>(Colors.black),
        ),
      ),
    );
  },
);

Afterwards I push a page.

await goRouter.push(
  const RouteEditPage().location,
  extra: (
    ...
  ),
);

I want the new page to be above the loading spinner. Because in this page I add some values and get return values back or an error. And after the page is closed the spinner should still be going for a while until some process finished.

At the moment the loading dialog is always on top. Even though I push the page later the dialog seems to be at the topmost spot at the stack.

How can I change that?


Solution

  • showDialog has a property named useRootNavigator which is set to true by default and which will make the dialog to be the top most route. Try setting it to false to prevent it from being above the latest pushed route.