简体   繁体   English

Go_Router,如何在上一页获取结果

[英]Go_Router, How to get result in previous page

In my project i am setting up go_router navigation and it works great for navigate, but i found two issues in two cases which i am mentioning below.在我的项目中,我正在设置 go_router 导航,它非常适合导航,但我在下面提到的两种情况下发现了两个问题。

  1. Not found a proper way to pass result in previous page未找到在上一页中传递结果的正确方法

I have created a common function for routing in the whole app where i have defined all methods push, pop, remove.我在整个应用程序中创建了一个通用的 function 路由,我在其中定义了所有推送、弹出、删除方法。 Now i need to setup a common method where i can pass some data into other screen and also need to get result in previos page when the second screen pop will going to be called.现在我需要设置一个通用方法,我可以将一些数据传递到其他屏幕,并且还需要在调用第二个屏幕弹出窗口时在 previos 页面中获取结果。

static go(
  {required BuildContext context,
  required Mode mode,
  required String moveTo,
  var param}) async {
try {
  switch (mode) {
    case Mode.PUSH:
      context.push(RouteName.root + moveTo);
      break;
    case Mode.REPLACE:
      context.pushReplacement(RouteName.root + moveTo);
      break;
    case Mode.REMOVE:
      context.go(RouteName.root);
      context.pushReplacement(RouteName.root + moveTo);
      break;
    case Mode.POP:
      context.pop();
      break;
  }
} catch (e) {
  print(e);
}

} }

  1. How to get page info during routing如何在路由过程中获取页面信息

In go_router i am unable to find a way where i can get the current page information if i pop the screen B to screen A. I need to track user activity so in this case i need to fetch the route info when user go or back into any screen.在 go_router 中,如果我将屏幕 B 弹出到屏幕 A,我无法找到获取当前页面信息的方法。我需要跟踪用户活动,因此在这种情况下,我需要在用户 go 或返回时获取路由信息任何屏幕。 Please guide me if there is any way with go_router.如果 go_router 有任何方法,请指导我。

As far as I know there is currently no way to do this.据我所知,目前没有办法做到这一点。 But someone have made a fork repo & implemented it which you can use.但是有人制作了一个 fork repo 并实现了它,你可以使用它。

Its on pub.dev with the name go_router_flow .它在 pub.dev 上,名称为go_router_flow It's exactly like the original go_router with this pop with value feature.它与具有此 pop with value 功能的原始 go_router 完全一样。

Here is some example code:这是一些示例代码:

final bool? result = await context.push<bool>('/page2');

WidgetsBinding.instance.addPostFrameCallback((_) {
  if(result){
    print('Page returned $result');
  }
});

You can read the discussion here你可以在这里阅读讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM