Skip to content

go_router_builder does not add observers to StatefulShellBranchData #143869

@rubenlop88

Description

@rubenlop88

Steps to reproduce

  1. Create a new project and add the go_router_builder dependencies
  2. Create a tab_routes.dart file with this content:
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

part 'tab_routes.g.dart';

@TypedStatefulShellRoute<MainShellRoute>(
  branches: <TypedStatefulShellBranch<StatefulShellBranchData>>[
    TypedStatefulShellBranch<HomeTabData>(
      routes: <TypedRoute<RouteData>>[
        TypedGoRoute<HomeRoute>(path: '/home'),
      ],
    ),
  ],
)
class MainShellRoute extends StatefulShellRouteData {
  const MainShellRoute();

  @override
  Widget builder(
      BuildContext context,
      GoRouterState state,
      StatefulNavigationShell navigationShell,
      ) {
    return Scaffold(body: navigationShell);
  }
}

class HomeRoute extends GoRouteData {
  @override
  Widget build(BuildContext context, GoRouterState state) {
    return Container();
  }
}

class HomeTabData extends StatefulShellBranchData {
  static final List<NavigatorObserver> $observers = [
    DummyNavigatorObserver(),
  ];
}

class DummyNavigatorObserver extends NavigatorObserver {}
  1. Run flutter pub run build_runner build --delete-conflicting-outputs

Expected results

A generated file where observers is passed as a parameter:

RouteBase get $mainShellRoute => StatefulShellRouteData.$route(
      factory: $MainShellRouteExtension._fromState,
      branches: [
        StatefulShellBranchData.$branch(
          observers: HomeTabData.$observers,
          routes: [
            GoRouteData.$route(
              path: '/home',
              factory: $HomeRouteExtension._fromState,
            ),
          ],
        ),
      ],
    );

Actual results

A generated file where observers is not passed as a parameter:

RouteBase get $mainShellRoute => StatefulShellRouteData.$route(
      factory: $MainShellRouteExtension._fromState,
      branches: [
        StatefulShellBranchData.$branch(
          routes: [
            GoRouteData.$route(
              path: '/home',
              factory: $HomeRouteExtension._fromState,
            ),
          ],
        ),
      ],
    );

Code sample


import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

part 'tab_routes.g.dart';

@TypedStatefulShellRoute<MainShellRoute>(
  branches: <TypedStatefulShellBranch<StatefulShellBranchData>>[
    TypedStatefulShellBranch<HomeTabData>(
      routes: <TypedRoute<RouteData>>[
        TypedGoRoute<HomeRoute>(path: '/home'),
      ],
    ),
  ],
)
class MainShellRoute extends StatefulShellRouteData {
  const MainShellRoute();

  @override
  Widget builder(
      BuildContext context,
      GoRouterState state,
      StatefulNavigationShell navigationShell,
      ) {
    return Scaffold(body: navigationShell);
  }
}

class HomeRoute extends GoRouteData {
  @override
  Widget build(BuildContext context, GoRouterState state) {
    return Container();
  }
}

class HomeTabData extends StatefulShellBranchData {
  static final List<NavigatorObserver> $observers = [
    DummyNavigatorObserver(),
  ];
}

class DummyNavigatorObserver extends NavigatorObserver {}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel stable, 3.16.9, on macOS 14.1.2 23B92 darwin-arm64, locale es-419)
    ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.2.6/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/rubenlopez/fvm/versions/stable. Consider adding /Users/rubenlopez/fvm/versions/stable/bin to the front of your path.
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.4)
[✓] VS Code (version 1.85.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    found in release: 3.19Found to occur in 3.19found in release: 3.20Found to occur in 3.20has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: go_router_builderThe go_router_builder packagepackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions