Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Auto generate AutoRoute List #2123

Open
lwj1994 opened this issue Jan 7, 2025 · 3 comments
Open

[Feature Request] Auto generate AutoRoute List #2123

lwj1994 opened this issue Jan 7, 2025 · 3 comments

Comments

@lwj1994
Copy link

lwj1994 commented Jan 7, 2025

Thank you very much for this library. I have a requirement when using it.
Every time a new page is added, I have to manually add AutoRoute(path: "xxx", page: XXRoute.page). Can the generation of List<AutoRoute> routes be automatically completed by build_runner by default?

Add a path arg in RoutePage.
for example:

@RoutePage(
  path: '/test',
)
class TestPage extends StatelessWidget

then generate in app_router.gr.dart:

/// app_router.gr.dart
List<AutoRoute> get _generateRoutes => [AutoRoute(path: "/test", page: TestRoute.page)];

/// app_router.dart
class AppRouter extends RootStackRouter {
  @override
  final List<AutoRoute> routes = _generateRoutes
}
@ricardodalarme
Copy link

This would be amazing!

@lwj1994
Copy link
Author

lwj1994 commented Jan 8, 2025

It's possible that this approach would necessitate shifting all CustomRoute configurations to the Page.

CustomRoute maybe convert to CustomRouteConfig

mixin CustomRouteConfig {
  RouteTransitionsBuilder? transitionsBuilder() {
    return null;
  }

  @protected
  String path() {
    return "";
  }
}

@RoutePage(path: '/test',)
class TestPage extends StatelessWidget with CustomRouteConfig {
  @override
  Widget build(BuildContext context) {
    return Container();
  }

  @override
  RouteTransitionsBuilder? transitionsBuilder() {
    return TransitionsBuilders.noTransition;
  }
}

@navaronbracke
Copy link

Hopefully we can address this with https://dart.dev/language/macros

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants