How to reuse same screen reused in multiple sub-routes with GoRouter
12:39 04 Jan 2024

I have following navigation use case, which I find problematic to implement with GoRouter.

  1. All the modules (like Schedule, Sales Order, etc.) can appear either in BottomNavigationBar or under More. How to reuse them without duplicating all of their subroutes? This kinda forces you to work with context.push in an imperative way. Because the route name must be unique, you can't use names at all (at least not in a way where they are reused both for StatfulShell and More subroutes).

  2. We have sort-of circular dependency where from case you can go to sales order (case/:id/sales-order/:sid) and vice-versa (sales-order/:sid/case/:id). I plan to programmatically prevent infinite navigation, but with GoRouter you need to declare all of your routes before-hand, making it impossible to reuse. You need to duplicate this manually do avoid circular dependency.

What I expected coming into GoRouter, is ability to define my modules (like Schedule, SalesOrders, etc.) since these modules work in isolation. And then it's just a matter of combining the modules into navigation, where they can be reused from multiple places. But, I've found this impossible to do.

Is there anything I'm missing here that could help me implement this?

enter image description here

flutter flutter-navigation flutter-go-router