flutter auto route build runner error Route must have either a page or a redirect destination

Viewed 1821

when i add a new route to router.dart and run the build runner i get the Route must have either a page or a redirect destination Error

below is my code in router.drat :

 
@MaterialAutoRouter(
  replaceInRouteName: 'Page,Route',
  routes: <AutoRoute>[
    AutoRoute(
      path: '/',
      page: SplashPage,
    ),
    AutoRoute(
      path: 'signInPage',
      name: 'SignInRouter',
      page: SignInPage,
    ),
    AutoRoute(
      path: 'noteOverviewPage',
      name: 'NoteOverviewRouter',
      page: NoteOverviewPage,
    ),
    AutoRoute(
      path: 'todoFormPage',
      name: 'todoFormRouter',
      page: TodoFormPage,
    ),
  ],
)
class $AppRouter {}
2 Answers

There is also the possibility that you forgot to save the code of your new page (which happened to me). In that case your code might be there but the file is not yet saved so build runner will create this error.

Make sure that all pages are stateless widgets, not statefull widgets! This weird move helped me. Met this strange problem today, maybe it's bug.

Related