Getx: Hot reload replacing previous routes

Created on 28 May 2020  路  14Comments  路  Source: jonataslaw/getx

During development the hot reload replaces all previous routes with the current route
I'm not sure if this is a problem it self since I don't know if this will happen in the prod app, but at the moment everytime I go to a route and then change something there, I can't go back to the previous one.

Example
Suppose the following routes on the tree:
Home (tab) > Clients (tab) > ClientDetails (Route)

Expected behavior
When I do this and change nothing on VS Code (not hot reloading), everything works well, when I press the Back button or even call Get.back(), I navigate back to the Clients tab, and the widget ClientDetails is removed from the tree, the weird thing happens when I'm still on the ClientDetails and I change something, after hot reloading, when I look the widget tree I just see something like: ClientDetails > ClientDetails > ClientDetails
and when I press back I keep seing the same client page until the app closes.

Also when I go Home > Clients > ClientDetails then I pressess back it's okay, but if I hot reload, it just take me back to the ClientDetails page, wich weird, because if I delete a client than change something, it takes me back to the page of the deleted client.

To be sure that the ClientDetails is disposed, I changed it to a Statefull Widget and the dispose method is being called normally.

Screenshots
The tree before hot reloading:
before

The tree after hot reloading making any change in the code:
after

Flutter Version:
1.19.0-2.0.pre173

Get Version:
get: ^2.5.6

The phone:
Samsung S10+

All 14 comments

Well, that can be two things.
The first is: you are using the master, and the Flutter is going totally crazy with the change of Navigator 2.0.
I use the master too, but I stopped at 1.19.02 because of these inconsistencies.
The second is: GetMaterialApp is not the top widget in your app.
If it is outside the runApp, some unexpected behavior can happen.
I am thinking of removing the function "restartApp ', which I believe is not used as much, has not even been documented, and it is responsible for this behavior, since if a top level widget is used, it can change the key of the materialApp and generate unwanted behavior.

But first of all, are you using named routes, or common routes? onGenerateRoute, or namedRoutes, where is your GetMaterialApp?

This is the structure of my main:
runApp -> MyApp (stateFulWidget)
and in MyApp, I have the builder that returns a MultiProvider with GetMaterialApp as child. I'm using namedRoutes with onGenerateRoute to navigate. I'll try again using the Stable channel, if it still happens I'll then try to move the GetMaterialApp to be on the top of the tree.

Nothing, I switched to the Stable channel and replaced MyApp Widget with a function that returns the GetMaterialApp, in my widget tree I see: [root] -> GetMaterialApp -> MultiProvider... and yet, the same problem still persists :(

Although this is not a problem in production, as there will be no hotreload, this needs to be studied.
The big problem is that I can't reproduce this, the sample application has exactly the same behavior, it navigates between 3 routes, and it doesn't happen.
I will try to add the Provider to the equation to see if there is any incompatibility, which there shouldn't be, there are structures created with Get and provider like Stack_services, and this bug doesn't happen there either.

Although this is not a problem in production, as there will be no hotreload, this needs to be studied.
The big problem is that I can't reproduce this, the sample application has exactly the same behavior, it navigates between 3 routes, and it doesn't happen.
I will try to add the Provider to the equation to see if there is any incompatibility, which there shouldn't be, there are structures created with Get and provider like Stack_services, and this bug doesn't happen there either.

Well, I'll try to build a simple app and try to reproduce the problem, so I can share it.

Solved it, the problem was an inherited widget that I use to get the current route and decide which widget to show based on the screen size, when a route is poped, apparently settings.name still have of the old route, so when my inherited widget is rebuilded for any reason, it's getting this old route since it hasn't been updated, which creates this problem because it's causing all of my widgets to see the same route. I solved by passing the route name to this widget onGenerateRoute. I thought that poping a route it would cause the onRouteGenerate to update the current route name.

Glad you solved this on your own.
Get also has apis like Get.currentRoute to find out what the current route is.

Glad you solved this on your own.
Get also has apis like Get.currentRoute to find out what the current route is.

Ty, I tried Get.currentRoute, but it always returns null, I don't know why :/

This what I get from Get when I navigate to somewhere, or try to Get.currentRoute, is it normal?

Capturar

Glad you solved this on your own.
Get also has apis like Get.currentRoute to find out what the current route is.

Ty, I tried Get.currentRoute, but it always returns null, I don't know why :/

This what I get from Get when I navigate to somewhere, or try to Get.currentRoute, is it normal?

Capturar

I've never seen that in my life. Can you point me in what situations this occurs?
going to route null is such an exotic thing that even i being the creator of the library can intentionally reproduce this

A tip: update your version of Get. The version mentioned in the issue is very old.

Glad you solved this on your own.
Get also has apis like Get.currentRoute to find out what the current route is.

Ty, I tried Get.currentRoute, but it always returns null, I don't know why :/
This what I get from Get when I navigate to somewhere, or try to Get.currentRoute, is it normal?
Capturar

I've never seen that in my life. Can you point me in what situations this occurs?
going to route null is such an exotic thing that even i being the creator of the library can intentionally reproduce this

Basically everytime I use the Get.toNamed, it prints me that haha, I will update the version.

I too am facing a similar issue!

@mayukhsil, please, open new issue e provide a reprodution code

@eduardoflorence just did that!

Was this page helpful?
0 / 5 - 0 ratings