inlavigo / gg_router

A lightweight routing system for flutter
BSD 2-Clause "Simplified" License
4 stars 0 forks source link

allow pages to stop from navigating away, e.g. if there are unsaved state changes #2

Open ghost opened 3 years ago

ghost commented 3 years ago

Hello, I am going to start a web project with Flutter, for another project use the Fluro library, however, I could not solve the following problem: If a user is on a page that contains a form and is making modifications is said form, I would like that if he tries to exit without having saved the modifications (either by putting another url, with the browser's backbutton, ...) it would show him an alertdialog giving him the possibility of canceling the navigation to the new url or, on the contrary, of canceling the modifications and staying on the same page where he is. The question is, can I do this with gg_router? gg_router has any mechanism by which this functionality can be achieved? Please, if this functionality is possible with gg_router could you give me some indications. Thank you so much for all the help. Regards, Jose

gatzsche commented 3 years ago

Hi Jose,

currently, there is no mechanism built-in allowing you to intercept navigation actions. But I'm open to implementing one. Do you have suggestions how the mechanism could look like?

Best, Gabriel

ghost commented 3 years ago

Hi Gabriel, Perhaps in the CgNavigationPage widget an event could be added that will be fired when the user is going to leave the page, in this event it could be indicated whether or not navigation to the new page is canceled. What do you think about this? Best Jose