getx icon indicating copy to clipboard operation
getx copied to clipboard

Back Button in Multiple Views Deletes Shared Controller

Open seljad opened this issue 1 year ago • 11 comments

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 avatar Aug 26 '23 12:08 seljad

any idea? @jonataslaw

seljad avatar Aug 29 '23 07:08 seljad

Are you using onGenerateRoute and Navigator widget?

jonataslaw avatar Aug 31 '23 01:08 jonataslaw

Are you using onGenerateRoute and Navigator widget?

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

seljad avatar Aug 31 '23 09:08 seljad

Thank you! let me have a look at this

jonataslaw avatar Sep 01 '23 00:09 jonataslaw

Thank you! let me have a look at this

I'm waiting for your response

seljad avatar Sep 01 '23 15:09 seljad

Hi @seljad, Do you find any solution?

hareendranmg avatar Sep 26 '23 01:09 hareendranmg

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.

seljad avatar Sep 26 '23 08:09 seljad

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

jonataslaw avatar Sep 26 '23 20:09 jonataslaw

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 avatar Sep 27 '23 07:09 seljad

@jonataslaw is this fix in version 5?

seljad avatar Nov 17 '23 09:11 seljad

@jonataslaw facing the same problem

wildsurfer avatar Dec 04 '23 07:12 wildsurfer