How to solve GoRouter.routeInformationProvider missing error?

Viewed 1913

The flutter team has given the following flutter project created by them, to learn from. https://github.com/flutter/codelabs/tree/main/boring_to_beautiful through their codelab.

I cloned the repo and tried to start the app. But it throws the following error.

════════ Exception caught by widgets library The following assertion was thrown building IconTheme(color: Color(0xdd000000)): This GoRouteInformationParser needs to be used with GoRouteInformationProvider, did you forget to pass in GoRouter.routeInformationProvider to the Router constructor? 'package:go_router/src/go_route_information_parser.dart': package:go_router/src/go_route_information_parser.dart:1 Failed assertion: line 148 pos 13: 'routeInformation is DebugGoRouteInformation'

From this error msg, I could understand that 'routeInformationProvider' seems to be missing. But is that possible in a working demo project given by the flutter team to learn from? Should I pass the routeInformationProvider? if so any docs, please.

5 Answers

Just add routeInformationProvider to MaterialApp.router.

Example:

  final _router = GoRouter(
         ...
  );

  @override
  Widget build(BuildContext context) {
      return MaterialApp.router(
          routeInformationProvider: _router.routeInformationProvider,
          ...
       );
   }

I also had this problem, but with the go_router version: ^4.1.0 and following this guide the problem is solved.

Just go back to version 3.1.1 of GoRouter. It seems latest version has an issue

Add routeinformationProvider at MaterialApp root:

MaterialApp.router(
  routeInformationProvider: goRouter.routeInformationProvider,//Add this line
  routerDelegate: goRouter.routerDelegate,
  routeInformationParser: goRouter.routeInformationParser,
  debugShowCheckedModeBanner: false,
  theme: ThemeData(
    primarySwatch: Colors.amber,
  ),
);

For me, it was solved when I added

the following line of code

routeInformationProvider: _router.routeInformationProvider,

before the following two lines of codes

routeInformationParser: goRouter.routeInformationParser,
routerDelegate: goRouter.routerDelegate,
Related