Skip to content

[go_router_builder] GoRouterState referencing removed getter queryParameters #131189

@techouse

Description

@techouse

Is there an existing issue for this?

Steps to reproduce

  1. install
go_router: 10.0.0
go_router_builder: 2.2.3
  1. make a typed route with an optional parameter (query var)
@TypedGoRoute<HomeRoute>(path: '/home')
class HomeRoute extends GoRouteData {
  const HomeRoute({ this.trackingId });

  final String? trackingId;

  @override
  Widget build(BuildContext context, GoRouterState state) => HomeScreen(trackingId: trackingId);
}
  1. run code generation
flutter pub run build_runner build --delete-conflicting-outputs
  1. running the app produces
Failed to build iOS app
Could not build the precompiled application for the device.
Error (Xcode): lib/src/router/routes.g.dart:32:19: Error: The getter 'queryParameters' isn't defined for the class 'GoRouterState'.

Expected results

The generated Dart file should point to state.uri.queryParameters not state.queryParameters.

RouteBase get $homeRoute => GoRouteData.$route(
      path: '/home',
      factory: $HomeRouteExtension._fromState,
    );

extension $HomeRouteExtension on HomeRoute {
  static HomeRoute _fromState(GoRouterState state) => HomeRoute(
        trackingId: state.uri.queryParameters['tracking-id'], // it should reference the Uri here
      );

  String get location => GoRouteData.$location(
        '/home',
        queryParams: {
          if (trackingId != null)
            'tracking-id': trackingId,
        },
      );

  void go(BuildContext context) => context.go(location);

  Future<T?> push<T>(BuildContext context) => context.push<T>(location);

  void pushReplacement(BuildContext context) =>
      context.pushReplacement(location);

  void replace(BuildContext context) => context.replace(location);
}

Actual results

RouteBase get $homeRoute => GoRouteData.$route(
      path: '/home',
      factory: $HomeRouteExtension._fromState,
    );

extension $HomeRouteExtension on HomeRoute {
  static HomeRoute _fromState(GoRouterState state) => HomeRoute(
        trackingId: state.queryParameters['tracking-id'], // references removed queryParameters getter
      );

  String get location => GoRouteData.$location(
        '/home',
        queryParams: {
          if (trackingId != null)
            'tracking-id': trackingId,
        },
      );

  void go(BuildContext context) => context.go(location);

  Future<T?> push<T>(BuildContext context) => context.push<T>(location);

  void pushReplacement(BuildContext context) =>
      context.pushReplacement(location);

  void replace(BuildContext context) => context.replace(location);
}

Code sample

@TypedGoRoute<HomeRoute>(path: '/home')
class HomeRoute extends GoRouteData {
  const HomeRoute({ this.trackingId });

  final String? trackingId;

  @override
  Widget build(BuildContext context, GoRouterState state) => HomeScreen(trackingId: trackingId);
}

Screenshots or Video

No response

Logs

Logs
Failed to build iOS app
Could not build the precompiled application for the device.
Error (Xcode): lib/src/router/routes.g.dart:32:19: Error: The getter 'queryParameters' isn't defined for the class 'GoRouterState'.

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.3 22E252 darwin-x64, locale en-GB)
    • Flutter version 3.10.6 on channel stable at /usr/local/Caskroom/flutter/3.10.6/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (12 days ago), 2023-07-12 15:19:05 -0700
    • Engine revision cdbeda788a
    • Dart version 3.0.6
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/techouse/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • ANDROID_HOME = /Users/techouse/Library/Android/sdk
    • Java binary at: /Users/techouse/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.10121639/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Users/techouse/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.10121639/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] IntelliJ IDEA Community Edition (version 2023.1.4)
    • IntelliJ at /Users/techouse/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/231.9225.16/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.75.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • macOS (desktop)          • macos                     • darwin-x64     • macOS 13.3 22E252 darwin-x64
    • Chrome (web)             • chrome                    • web-javascript • Google Chrome 114.0.5735.198

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

Labels

P1High-priority issues 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_routerThe go_router packagep: go_router_builderThe go_router_builder packager: 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