7

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 {}

5 Answers5

13

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.

Rob van Putten
  • 349
  • 1
  • 5
1

I fix this it, removing and re-import class patch

Afanasov S
  • 39
  • 1
0

in android studio when build-runner runs especially when runs in watch mode . you must save the files related to build-runner by Ctrl+S and wait to build-runner recompile files to save the changes. (you can see in android studio terminal).

so you should open these files and then press Ctrl+S on it: SplashPage , SignInPage , NoteOverviewPage , TodoFormPage , router.drat

mhKarami
  • 844
  • 11
  • 16
-1

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.

Zotov
  • 71
  • 1
  • 5
-1

In my case, I renamed one page, changed the uppercase letter to a small one (file name), and it ended up with a capital letter in the import and flutter didn't complain about it, so nothing worked. Just delete all the imports and do the imports again.