jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.43k stars 1.63k forks source link

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

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 getx? getx has any mechanism by which this functionality can be achieved? Please, if this functionality is possible with getx could you give me some indications. Thank you so much for all the help. Regards, Jose

maares commented 3 years ago

@Josua2012 this questions is more related to flutter framework, not GetX package, I recommend sites like Stack-overflow as most probably this question is already answer there.

Non the less, what you are searching for is in the library "dart:html", which contains all (i think) methods used to work with DOM objects in particularly you need to use the class window.

import 'dart:html' as html;
html.window.onBeforeUnload.listen((event) async{
  // do something
});
ghost commented 3 years ago

@maares But shouldn't a library like GetX that have routing support incorporate this feature? Thanks. Regards, Jose

maares commented 3 years ago

@Josua2012 I´m a novice on flutter really, what I mention is for the use case when user closes the tab or browser. I´m not aware that navigation 2.0 has it´s own methods to detect, for instance when a tab is closed, please send link to learn from it.

On my opinion it could be implemented on GetX, but bare in mind web is relatively new. GetX as mentions on the read me section is more than state management, but that does not mean, it will re-implement in a more convenient way in advance, all available features that already exists on flutter framework libraries.

Think it more as a road-map, as this library implemented GetConnect hopefully in the future it will continue to implement more functionality in order to make our development easier.