Skip to content

[go_router_builder] Required query parameters are not included in the location #128483

@ValentinVignal

Description

@ValentinVignal

Is there an existing issue for this?

The PR flutter/packages#4039 introduced a bug where the required query parameters are not included in the location.

Steps to reproduce

  1. Run the flutter test on the code example below

Expected results

I would expect the query parameter to be included in the locatio

Actual results

The query parameter is not included in the location.

Code sample

Code sample

You can checkout https://github.com/ValentinVignal/flutter_app_stable/tree/go-router-builder/missing-required-query-parameter-in-location

// lib/routes.dart

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

part 'routes.g.dart';

@TypedGoRoute<MyRoute>(
  path: '/my-route',
)
class MyRoute extends GoRouteData {
  const MyRoute({
    required this.requiredQueryParameter,
  });

  final String requiredQueryParameter;

  @override
  Widget build(BuildContext context, GoRouterState state) =>
      const Placeholder();
}

It generates:

// lib/routes.g.dart

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'routes.dart';

// **************************************************************************
// GoRouterGenerator
// **************************************************************************

List<RouteBase> get $appRoutes => [
      $myRoute,
    ];

RouteBase get $myRoute => GoRouteData.$route(
      path: '/my-route',
      factory: $MyRouteExtension._fromState,
    );

extension $MyRouteExtension on MyRoute {
  static MyRoute _fromState(GoRouterState state) => MyRoute(
        requiredQueryParameter:
            state.queryParameters['required-query-parameter']!,
      );

  String get location => GoRouteData.$location(
        '/my-route',
      );

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

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

  void pushReplacement(BuildContext context) =>
      context.pushReplacement(location);
}
// test file

import 'package:flutter_app_stable/routes.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  test('It should include the query parameters in the location', () {
    expect(
      const MyRoute(requiredQueryParameter: 'requiredQueryParameter').location,
      '/my-route?requiredQueryParameter=requiredQueryParameter',
    );
  });
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
00:12 +0 -1: It should include the query parameters in the location [E]                                                                                                                                                                         
  Expected: '/my-route?requiredQueryParameter=requiredQueryParameter'
    Actual: '/my-route'
     Which: is different. Both strings start the same, but the actual value is missing the following trailing characters: ?requiredQ ...
  
  package:test_api                                    expect
  package:flutter_test/src/widget_tester.dart 460:16  expect
  test/widget_test.dart 13:5                          main.<fn>
  

To run this test again: /Users/valentin/flutter/flutter/bin/cache/dart-sdk/bin/dart test /Users/valentin/Perso/Projects/flutter_app_stable/test/widget_test.dart -p vm --plain-name 'It should include the query parameters in the location'
00:12 +0 -1: Some tests failed. 

Flutter Doctor output

Doctor output
[!] Flutter (Channel stable, 3.7.12, on macOS 13.3.1 22E772610a darwin-x64, locale en-GB)
    • Flutter version 3.7.12 on channel stable at /Users/valentin/flutter/flutter
    ! Warning: `dart` on your path resolves to /usr/local/Cellar/dart/2.18.3/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/valentin/flutter/flutter. Consider adding /Users/valentin/flutter/flutter/bin to
      the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4d9e56e694 (7 weeks ago), 2023-04-17 21:47:46 -0400
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /usr/local/Caskroom/android-sdk/4333796
    • Platform android-33, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • 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 2021.1)
    • Android Studio at /Applications/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 11.0.11+0-b60-7590822)

[✓] VS Code (version 1.78.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.66.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 13.3.1 22E772610a darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 114.0.5735.106

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Metadata

Metadata

Labels

found in release: 3.10Found to occur in 3.10found in release: 3.12Found to occur in 3.12has 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

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions