Mg Bhadurudeen
Mg Bhadurudeen

Reputation: 1434

How to solve GoRouter.routeInformationProvider missing error?

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.

Upvotes: 9

Views: 7551

Answers (6)

Ali Anando
Ali Anando

Reputation: 31

adding routeInformationProvider in addition to routeInformationParser and routerDelegate solved my problem.

routeInformationProvider: _router.routeInformationProvider,
routeInformationParser: _router.routeInformationParser,
routerDelegate: _router.routerDelegate

Upvotes: 3

ArnaudR
ArnaudR

Reputation: 1992

Edit: - This should not be marked as the correct answer, as it was just a workaround. Please mark Luca Iaconelli answer as the correct one

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

Upvotes: 4

user2049634
user2049634

Reputation: 41

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,

Upvotes: 2

Miguel Rosal
Miguel Rosal

Reputation: 189

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,
  ),
);

Upvotes: 4

Luca Iaconelli
Luca Iaconelli

Reputation: 743

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

Upvotes: 9

baihu92
baihu92

Reputation: 496

Just add routeInformationProvider to MaterialApp.router.

Example:

  final _router = GoRouter(
         ...
  );

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

Upvotes: 37

Related Questions