Unhandled Exception: AutoRouter operation requested with a context that does not include an AutoRouter

Hello hello

I’m getting this error: Unhandled Exception: AutoRouter operation requested with a context that does not include an AutoRouter. The context used to retrieve the Router must be that of a widget that is a descendant of an AutoRouter widget.

Any idea how I can fix it please ?

I already asked on Stackoverflow, but I got no answer :frowning:

class App extends StatefulWidget {
  late AppRouter _appRouter;
  late KeycloakAuth _auth;

  App(KeycloakAuth auth, {Key? key}) : super(key: key) {
    _auth = auth;
    _appRouter = AppRouter(authGuard: AuthGuard(_auth));
  }

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> with TickerProviderStateMixin {
  late final AnimationController _controller;

  @override
  void initState() {
    super.initState();

    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
          create: (_) => widget._auth,
        ),
        ChangeNotifierProvider(
          create: (_) => PaymentIntentProvider(),
        ),
        BlocProvider<ItemCategoriesBloc>(
            create: (context) =>
                ItemCategoriesBloc(APIProvider.backendAPI)..add(LoadItemCategoriesEvent())),
        BlocProvider<NgosBloc>(
            create: ((context) => NgosBloc(APIProvider.backendAPI)..add(LoadNgosEvent()))),
        BlocProvider<ProfileBloc>(create: (context) => ProfileBloc(APIProvider.backendAPI)),
        BlocProvider<PrivateProfileBloc>(
            create: (context) => PrivateProfileBloc(APIProvider.backendAPI, widget._auth.userId)
              ..add(LoadPrivateProfile())),
        BlocProvider<ItemBloc>(create: (context) => ItemBloc(APIProvider.backendAPI)),
        BlocProvider<ItemsListBloc>(
            create: (context) => ItemsListBloc(APIProvider.backendAPI)..add(LoadItemsList())),
        BlocProvider<ConversationBloc>(
            create: (context) => ConversationBloc(APIProvider.backendAPI)),
        BlocProvider<ConversationsListBloc>(
            create: (context) =>
                ConversationsListBloc(APIProvider.backendAPI)..add(LoadConversationsList())),
        BlocProvider<SearchBloc>(create: (context) => SearchBloc(APIProvider.backendAPI)),
      ],
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'TrödelSpende',
        home: AnimatedSplashScreen(
          animationDuration: const Duration(seconds: 7),
          splashIconSize: double.maxFinite,
          splash: Lottie.asset(
            'assets/Logo-3-[remix]-[remix].json',
          ),
          nextScreen: MaterialApp.router(
            debugShowCheckedModeBanner: false,
            theme: MyTheme.create(),
            localizationsDelegates: context.localizationDelegates,
            supportedLocales: context.supportedLocales,
            locale: context.locale,
            routerDelegate: AutoRouterDelegate(widget._appRouter,
                navigatorObservers: () => [AutoRouteObserver()]),
            routeInformationProvider: widget._appRouter.routeInfoProvider(),
            routeInformationParser: widget._appRouter.defaultRouteParser(),
          ),
        ),
      ),
    );
  }
}

Thank you in advance for your help :smiley:

In your providers list, it seems to have a rogue opening parentheses create: ((context) => NgosBloc

And a closing parentheses can be removed at the end of the line ..add(LoadNgosEvent())))

So
create: (context) => NgosBloc
And
..add(LoadNgosEvent()))

Thank you for your answer but I don’t think that’s what is causing the error :frowning: