starter_architecture_flutter_firebase icon indicating copy to clipboard operation
starter_architecture_flutter_firebase copied to clipboard

Add AppRouteObserver and route name to all pageBuilders

Open bizz84 opened this issue 11 months ago • 0 comments

This PR shows how to add a NavigatorObserver to GoRouter-based apps.

Unfortunately, adding observers: [AppRouterObserver()] is not enough and all route names will be null, unless an explicit name is added inside the pageBuilder:

GoRoute(
  path: '/jobs',
  name: AppRoute.jobs.name,
  pageBuilder: (context, state) => NoTransitionPage(
    // without this, the NavigatorObserver will report route name == null
    name: AppRoute.jobs.name,
    child: JobsScreen(),
  ),
)

But there are still cases where it doesn't work reliably. See this issue for more details: https://github.com/flutter/flutter/issues/112185

bizz84 avatar Jan 11 '25 18:01 bizz84