Skip to content

Generated code adds const keyword to shell constructor which causes compilation to fail #131211

@gibahjoe

Description

@gibahjoe

Is there an existing issue for this?

What package does this bug report belong to?

go_router_builder

What target platforms are you seeing this bug on?

Android, iOS, Web, macOS, Linux, Windows

Have you already upgraded your packages?

Yes

Dependency versions

pubspec.lock
[Paste file content here]

Steps to reproduce

  1. install
go_router: 10.0.0
go_router_builder: 2.2.3
  1. make a ShellRoute without const constructor
@TypedShellRoute<AppShell>(
  routes: <TypedRoute<RouteData>>[
      ],
)
class AppShell extends ShellRouteData {
  
  @override
  Widget builder(BuildContext context, GoRouterState state, Widget navigator) {
    // TODO: implement builder
    return AppLayout(
      child: navigator,
    );
  }
}
  1. run code generation
flutter pub run build_runner build --delete-conflicting-outputs

Expected results

The expected result is that the generated source compiles

Actual results

The generated source does not compile because the builder adds const keyword when it generates the code.

Code sample

Code sample
/// AppShell without const constructor
class AppShell extends ShellRouteData {
  
  @override
  Widget builder(BuildContext context, GoRouterState state, Widget navigator) {
    // TODO: implement builder
    return AppLayout(
      child: navigator,
    );
  }
}

/// Generated code that does not compile because of the const keyword

extension $AppShellExtension on AppShell {
  static AppShell _fromState(GoRouterState state) => const AppShell();
}

Screenshots or Videos

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.6, on macOS 14.0 23A5286i darwin-arm64, locale en-NG)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.3)
[✓] VS Code (version 1.80.1)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13has 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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions