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

when we using bottom Sheet and alert dialog it can't pop out the dialog #101

Closed anandrajak2 closed 1 year ago

SchabanBo commented 1 year ago

Hi @anandrajak2, What can not pop out, could you add an example?

westlinkin commented 1 year ago

I have the same problem. When I use modal_bottom_sheet showCupertinoModalBottomSheet shows a bottomSheet, then click the back button on the Android device, it clears the bottomSheet and pops back to previous screen (or exit the app if it is the root screen)

If I use Navigator.of(context).push(Route) to navigate to another screen, the back button works fine (pops out the bottomSheet only, do not pops to previous screen together). But If I use QR.to(screen_path), it doesn't work. (both pops the bottomSheet and pops to previous screen)

After a little dig into modal_bottom_sheet, I found out it use Navigator.of(context).push(Route) to show the bottomSheet, but when using qlevar_router, how to tell the navigator to handle the 'back button' correctly?

SchabanBo commented 1 year ago

Hi @westlinkin, Thanks for your feedback, I have found the problem and working on it

westlinkin commented 1 year ago

@SchabanBo

Thanks. I found a workaround, back_button_interceptor is needed. In every screen, check if a ModalRoute is active, if so, pops that ModalRoute and consumes the back button event; if not, do not do anything.

ModalRoute.of(context)?.isCurrent != true means a ModalRoute is presented (need to intercept the back button event)

SchabanBo commented 1 year ago

Exactly @westlinkin, that was the problem. When you add a buttom_sheet, this is done with Navigator.push. In this case, qlevar_router does not know that there is something else that should be removed and removes the last route. So I am trying to add a way for qlevar_router to check first if there are any other routes added from outside the package. But it is good that you have found something to fix it now.