Auto Generated Graphs #1911
Replies: 5 comments 4 replies
-
You said that you want to implement this so we don't have to edit and manage 2 separate files for our routing needs. I assume you mean one file where the route widget is defined with the But in your proposed solution, we still have the widget with the annotation and the configuration. Other than the obvious syntax change, aren't we still working with two files in the proposed idea? |
Beta Was this translation helpful? Give feedback.
-
@muezz well... with the new approach, you'd only write the global guard logic, I think it matters most when you first start scaffolding your App, you'd need to create screens on the fly, but let's hear more thoughts. |
Beta Was this translation helpful? Give feedback.
-
I think the proposal sound good, but I see there is a slight issue with the example provided. There is only one root page in the example, but what if there were multiple root pages? I think it would be great if you could add multiple hosts like |
Beta Was this translation helpful? Give feedback.
-
@Milad-Akarie class AppRouterEx extends AppRouter {
List<AutoRoute> _routes = [];
AppRouterEx({super.navigatorKey});
List<AutoRoute> get superRoutes => super.routes;
@override
List<AutoRoute> get routes {
if (_routes.isEmpty) {
var lst = super.routes;
PageRouteInfo landing = NavigFlow.landing;
final landingRoute = lst.firstWhereOrNull((e) => e.name == landing.routeName);
final landingPath = landingRoute?.path ?? '';
if (landingRoute != null && landingPath != '/') {
lst.removeWhere((e) => e.name == landing.routeName);
final landingRouteNew = landingRoute.changePath('/');
lst.add(landingRouteNew);
if (isNotEmpty(landingPath)) lst.add(RedirectRoute(path: landingPath, redirectTo: '/'));
}
_routes = lst;
}
return _routes;
}
} |
Beta Was this translation helpful? Give feedback.
-
Been using the package for a while now, and I think what it mostly lacks is a “style guide” of how to tackle certain setups with nested routing. I believe that auto-generated The main reason I started using this package was, that I could clearly define my routes in a tree-like manner, just like I design my widgets. I am sorrowed that this clear and readable structure will be lost when everything is automatically defined in a I certainly love the idea of not having to manually edit 2 files in order to add a simple route, but I fear that the result might lack readability. I'll think about possible solutions for that, as I would love for this feature to happen! 🥳 |
Beta Was this translation helpful? Give feedback.
-
Hey everyone,
I know that I'm not the only one bothered by the fact that you need to edit at least two files to add a new route in the current setup of
auto_route
. I'm constantly brainstorming ideas on how to fix this issue because auto_route is meant to reduce boilerplate to a minimum.I've finally come up with an idea that I think is worth considering, even if it involves a few breaking changes here and there. But before I dive into it, I'd like to hear your thoughts.
The primary goal of auto_route 1.0 was to annotate any screen as routable and have the package take care of everything. However, challenges like nested navigation, passing instances of route-guards, and adding non-static customizations to routes made things a bit tricky. Essentially, we were stuck between having a simple API where you just add a static annotation to a screen or generating part of the code and having users build the nav-graph manually.
So, here's the proposal: a hybrid approach that combines the best of both worlds. You can create your nested navigation by simply annotating your routable screens, while still retaining the ability to customize everything if needed. In short, a highly customizable
NavGraph
will be generated for you.For example, let's say you want to create a
TabsScreen
that has a tab calledAccountScreen
, which also hosts nested tabs likeProfileScreen
, and so on. This is how it would be implemented using the new proposal.e.g let's say want to create a
TabsScreen
that has a tab calledAccountScreen
which is also a host for nested tabs [ProfileScreen
, ...], this's how it would be implemented using the new approach.after running the generator nav graphs will be generated automatically and this is how the very basic setup would look like:
to further custimize your routes you can override any route config and it's sub-nav graph if it has one
as you can see the generation phase will decide how the nav graph is built, we can go step further and make it possible to add custom graph entries or even whole graphs.
Before moving forward, I'd appreciate your feedback. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions