In version 6.0 AutoRoute aims for less generated code for more flexibility and less generation time.
1. Instead of using MaterialAutoRouter
, CupertinoAutoRouter
, etc, we now only have one annotation for our router which is @AutoRouterConfig()
and instead of passing our routes list to the annotation we now pass it to the overridable getter routes
inside of the generated router class and for the default route type you can override defaultRouteType
// @CupertinoAutoRouter
// @AdaptiveAutoRouter
// @CustomAutoRouter
@MaterialAutoRouter(
routes: <AutoRoute>[
// routes go here
],
)
class $AppRouter {}
@AutoRouterConfig()
class AppRouter extends $AppRouter {
@override
RouteType get defaultRouteType => RouteType.material(); //.cupertino, .adaptive ..etc
@override
List<AutoRoute> get routes => [
// routes go here
];
}
2. Passing page components as types is changed, now you'd annotate the target page with @RoutePage()
annotation and pass the generated result.page
to AutoRoute():
class ProductDetailsPage extends StatelessWidget {}
AutoRoute(page: ProductDetailsPage) // as Type
@RoutePage() // Add this annotation to your routable pages
class ProductDetailsPage extends StatelessWidget {}
AutoRoute(page: ProductDetailsRoute.page) // ProductDetailsRoute is generated
3. EmptyRoutePage
no longer exists, instead you will now make your own empty pages by extending the AutoRouter
widget
AutoRoute(page: EmptyRoutePage, name: 'ProductsRouter') // as Type
@RoutePage(name: 'ProductsRouter')
class ProductsRouterPage extends AutoRouter {}
AutoRoute(page: ProductsRouter.page)
4. Passing route guards is also changed now, instead of passing guards as types you now pass instances.
AutoRoute(page: ProfilePage, guards:[AuthGuard]) // as Type
AutoRoute(page: ProfilePage, guards:[AuthGuard(<params>)]) // as Instance