SchabanBo / qlevar_router

Manage you project Routes. Create nested routes. Simply navigation without context to your pages. Change only one sub widget in your page when navigating to new route.
MIT License
87 stars 22 forks source link

Force refresh issue when using alongside canPopFunc #120

Closed arindammitra06 closed 3 months ago

arindammitra06 commented 1 year ago

Hi There, Thanks for the awesome package. It makes our life much easier. I am currently facing a issue with navigation. My homepage route is at "/" and I have added back button check using canPopFunc() like below.

`QRoute( name: homePage,

      path: '/',
      builder: () => HomePage(),
      middleware: [
        QMiddlewareBuilder(
          redirectGuardFunc: (s) async {
            SharedPreferences prefs = await SharedPreferences.getInstance();
            int? initScreen = await prefs.getInt("initScreen");
            return initScreen == null ?  '/onboarding' : null;
          },

          canPopFunc: () async {
            AlertDialog dialog(BuildContext context) => ......//some code here
            final result = await showDialog<bool>(
                context: QR.context!, builder: dialog);
            return result ?? false;
          },
        )
      ],
      ),`

Now whenever I am trying to force refresh the page or probably do pushReplacement using QR.navigator.replaceLast('/'); the exit alert dialog in being triggered. Any way to stop this?

SchabanBo commented 3 months ago

Refreshing the page in the package, is removing it from the stack, adding it again. When removing a page, the "canPopFunc" is called.