getx icon indicating copy to clipboard operation
getx copied to clipboard

Get.rootDelegate.toNamed should not remove the current page?

Open ChauCM opened this issue 4 years ago • 21 comments
trafficstars

At first I use Get.toNamed('/some_page') to get the SomePage. It work fine, my current page is alive, its controller have never been deleted. When I use Get.back() the state stay as it is (scroll location).

I update my app to Nav2.0, and now using Get.rootDelegate.toNamed(Routes.SOME_PAGE), the getx log tell me that its controller is delete. When I pop the new page, the current page's (first page) controller is re-initialize and I lose its state (scroll location reset to 0).

The two toNamed call should not behave differently, isn't it? Is there a way for me to keep the current page alive?

ChauCM avatar Aug 19 '21 22:08 ChauCM

get version and flutter doctor, please

jonataslaw avatar Aug 19 '21 22:08 jonataslaw

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.4 20F71 darwin-arm, locale en)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.59.0)
[✓] Connected device (2 available)

get: ^4.3.8

ChauCM avatar Aug 19 '21 22:08 ChauCM

same but the Get.toNamed is not works with me when I use GetMaterialApp.router, is it works with you?

you can use: Get.rootDelegate.popRoute();

if you just want pop

AbdallahR99 avatar Aug 23 '21 21:08 AbdallahR99

I have also encountered this problem. There is too few documentation about GetRouterOutlet.

hightman avatar Aug 24 '21 13:08 hightman

My app code base has root and home module following the nav2 example. I try to remove the rootfrom modules and from app_pages.dart because I feel like It is not necessary for my app. Somehow the problem gone. Get.rootDelegate.toNamed(Routes.SOME_PAGE) behave exactly like Get.toNamed('/some_page'). All the controllers are no longer deleted and re-initialize between pages. So I'm closing this problem.

My root view

class RootView extends GetView<RootController> {
  @override
  Widget build(BuildContext context) {
    return GetRouterOutlet.builder(
      builder: (context, delegate, current) {
        return Scaffold(
          body: GetRouterOutlet(
            initialRoute: Routes.HOME,
            // anchorRoute: '/',
            // filterPages: (afterAnchor) {
            //   return afterAnchor.take(1);
            // },
          ),
        );
      },
    );
  }
}

ChauCM avatar Sep 02 '21 17:09 ChauCM

My app code base has root and home module following the nav2 example. I try to remove the rootfrom modules and from app_pages.dart because I feel like It is not necessary for my app. Somehow the problem gone. Get.rootDelegate.toNamed(Routes.SOME_PAGE) behave exactly like Get.toNamed('/some_page'). All the controllers are no longer deleted and re-initialize between pages. So I'm closing this problem.

but this will cause tabbar works dose not propertly, such as /home/products, /home/profile will not contain bottom bar.

hightman avatar Sep 06 '21 11:09 hightman

I had a similar problem just now, not sure if the same or not. It happened when/while using a showSearch. In the end, the "problem" was having my controller defined in the bindings via lazyPut, without fenix=true. Having this set to true, allows it to be created correctly.

dbadrian avatar Sep 06 '21 21:09 dbadrian

My app code base has root and home module following the nav2 example. I try to remove the rootfrom modules and from app_pages.dart because I feel like It is not necessary for my app. Somehow the problem gone. Get.rootDelegate.toNamed(Routes.SOME_PAGE) behave exactly like Get.toNamed('/some_page'). All the controllers are no longer deleted and re-initialize between pages. So I'm closing this problem.

but this will cause tabbar works dose not propertly, such as /home/products, /home/profile will not contain bottom bar.

Oh, now I know why I lost the bottom navigation bar. Have you find a way to fix it? Thinking about reopen this issue.

ChauCM avatar Sep 07 '21 15:09 ChauCM

I have read some codes about GetRouterOutlet, It seems impossible to solve this problem due to its implementation.

You can try to use another route management library named Routemaster.

Finally, I gave up nav 2 and continued to use old way.

from iPhone6艹

在 2021年9月7日,23:30,ChauCM @.***> 写道:

 My app code base has root and home module following the nav2 example. I try to remove the rootfrom modules and from app_pages.dart because I feel like It is not necessary for my app. Somehow the problem gone. Get.rootDelegate.toNamed(Routes.SOME_PAGE) behave exactly like Get.toNamed('/some_page'). All the controllers are no longer deleted and re-initialize between pages. So I'm closing this problem.

but this will cause tabbar works dose not propertly, such as /home/products, /home/profile will not contain bottom bar.

Oh, now I know why I lost the bottom navigation bar. Have you find a way to fix it? Thinking about reopen this issue.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

hightman avatar Sep 08 '21 03:09 hightman

I have read some codes about GetRouterOutlet, It seems impossible to solve this problem due to its implementation. You can try to use another route management library named Routemaster. Finally, I gave up nav 2 and continued to use old way. from iPhone6艹 在 2021年9月7日,23:30,ChauCM @.***> 写道:  My app code base has root and home module following the nav2 example. I try to remove the rootfrom modules and from app_pages.dart because I feel like It is not necessary for my app. Somehow the problem gone. Get.rootDelegate.toNamed(Routes.SOME_PAGE) behave exactly like Get.toNamed('/some_page'). All the controllers are no longer deleted and re-initialize between pages. So I'm closing this problem. but this will cause tabbar works dose not propertly, such as /home/products, /home/profile will not contain bottom bar. Oh, now I know why I lost the bottom navigation bar. Have you find a way to fix it? Thinking about reopen this issue. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

Routemaster looks promising, did you try it? How is the compatibility with getx? Why did you not end up using it?

WangHansen avatar Sep 08 '21 09:09 WangHansen

Nav2 implementation completely unusable!

  • Zero documentation
  • toNamed removes previous page -> no back navigation button, slow back navigation with button
  • Wirte route tree, initial routes, route naming is unclear and confusing, example not help in many cases (missing docs?)

westito avatar Sep 16 '21 06:09 westito

Nav2 implementation completely unusable!

* Zero documentation

* toNamed removes previous page -> no back navigation button, slow back navigation with button

* Wirte route tree, initial routes, route naming is unclear and confusing, example not help in many cases (missing docs?)

A proper documentation on Navigation 2 would be really appreciate @jonataslaw !

loic-hamdi avatar Nov 09 '21 09:11 loic-hamdi

After more than one year, I moved from getx to more matured libs just because of its problems with router and nav2

papmodern avatar Jan 16 '22 07:01 papmodern

After more than one year, I moved from getx to more matured libs just because of its problems with router and nav2

What do you use now?

WangHansen avatar Jan 16 '22 08:01 WangHansen

After more than one year, I moved from getx to more matured libs just because of its problems with router and nav2

Can you tell me what you use now?

VictorWork0209 avatar Feb 14 '23 02:02 VictorWork0209

fucking getx does not have any solution for just a back prees on rootDelegate ? @jonataslaw

kiaxseventh avatar Aug 28 '23 18:08 kiaxseventh

This might be helpful, a way around calling .backUntil() method and get back to the first route, then replace the current route

await Get.rootDelegate.backUntil(Routes.SIGNIN);
Get.rootDelegate.offNamed(Routes.MAIN_TABS);

niamulhasan avatar May 17 '24 20:05 niamulhasan

Is this issue resolved? I am also facing same issue. On go to new route it is deleting previous route

shambhu-sharan avatar Jul 05 '24 13:07 shambhu-sharan

Is this issue resolved? I am also facing same issue. On go to new route it is deleting previous route

Get.rootDelegate.offNamed("/route_name);

yuanxintaxon avatar Jul 09 '24 07:07 yuanxintaxon

Is this issue resolved? I am also facing same issue. On go to new route it is deleting previous route

Did you define participatesInRootNavigator as true in some pages? This will cause the navigator to only retain the pages on the path and not retain the history pages.

hightman avatar Jul 09 '24 13:07 hightman


Is this issue resolved? I am also facing same issue. On go to new route it is deleting previous route

Did you define participatesInRootNavigator as true in some pages? This will cause the navigator to only retain the pages on the path and not retain the history pages.

No I haven't defined

shambhu-sharan avatar Jul 09 '24 13:07 shambhu-sharan