MaterialApp.router not rebuilding its sub-routes

30 views Asked by At

I have an MaterialApp.router which is wrapped inside BlocBuilder, something like below.

BlocBuilder<MyCubit, MyState>(
  builder: (context, state) {
    debugPrint('Material app rebuilds :)');

    return MaterialApp.router(
      ...
      routerConfig: AppRouter.router, // instance of GoRouter
    );
  }

The AppRouter.router is defined as follows, where the initialLocation is set to /home. In the HomeScreen(), details of the current active user are showcased. The HomeScreen() also have a button that can change the current user, and consequently MyState also updates.

static final router = GoRouter(
  ...
  initialLocation: '/home',
  routes: <RouteBase>[
    GoRoute(path: '/test', pageBuilder: (_, __) => const TestWidgetScreen()),
    GoRoute(path: '/intro', pageBuilder: (_, __) => const IntroScreen()),
    GoRoute(path: '/home', pageBuilder: (_, __) => const HomeScreen()),
  ],
);

Whenever, the current user changes by tapping the button in HomeScreen(), MyState also updates and consequently the MaterialApp.router also rebuilds as it is dependent upon MyState. However, HomeScreen() not updates at all, even though it's parent, which is MaterialApp.router rebuilds. What is happing here, and what are the remedies ?

I have implemented a separate BlocBuilder in HomeScreen, which is working by the way.

0

There are 0 answers