jonataslaw / getx

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

Back Button in Multiple Views Deletes Shared Controller #2888

Open seljad opened 1 year ago

seljad commented 1 year ago

I have an app that contains a bottom-navigation bar with nested routing, utilizing the GetX ecosystem. Some of the views have the same controllers. When a user is in one of these views and clicks the back button, Get.back() is executed, resulting in the removal of both the view and the controller from memory.

My issue arises when I click on the back button of the first created view. The possible scenario is as follows: a user opens page A, which is the first item in the bottom navigation bar. GetX creates a controller for page A. If the user then moves to the second item in the bottom navigation bar and attempts to recreate view A, the view is indeed created and used the previously mentioned controller in memory.

Now, a problem occurs when the user clicks on the back button in the second item of bottom-navigation bar. This action leads to the removal of view A and the subsequent deletion of the controller from memory, despite another view with the same controller being connected to it.

I am using GetX version 4.6.5

autodraw 8_26_2023

look at this: https://github.com/seljad/getx-nesting-routes

seljad commented 1 year ago

any idea? @jonataslaw

jonataslaw commented 1 year ago

Are you using onGenerateRoute and Navigator widget?

seljad commented 1 year ago

Are you using onGenerateRoute and Navigator widget?

@jonataslaw look at this repo and video: https://github.com/seljad/getx-nesting-routes

jonataslaw commented 1 year ago

Thank you! let me have a look at this

seljad commented 1 year ago

Thank you! let me have a look at this

I'm waiting for your response

hareendranmg commented 1 year ago

Hi @seljad, Do you find any solution?

seljad commented 1 year ago

Hi @seljad, Do you find any solution?

No, It's too bad that something like this happens, And I am waiting for @jonataslaw to answer that.

jonataslaw commented 1 year ago

How do you create the controller? Get.put in the view, Binding, or GetBuilder widget?

seljad commented 1 year ago

How do you create the controller? Get.put in the view, Binding, or GetBuilder widget?

I have shared with you my project in here. as you see, I created a controller in binding with Get.lazyPut<HomeController>( () => HomeController(), );

seljad commented 11 months ago

@jonataslaw is this fix in version 5?

wildsurfer commented 11 months ago

@jonataslaw facing the same problem