skip to Main Content

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.

  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. 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.

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. Please guide me if there is any way with go_router.

2

Answers


  1. 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.

    Its on pub.dev with the name go_router_flow. It’s exactly like the original go_router with this pop with value feature.

    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

    Login or Signup to reply.
  2. The package had an update by the nice people 😁🥳 Update to 6.5.5 and checkout docs

    Waiting for a value:

    onTap: () {
      final bool? result = await context.push<bool>('/page2');
      if(result ?? false)...
    }`
    

    Returning a value:

    onTap: () => context.pop(true)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search