Skip to content

[go_router_builder] Route with an empty iterable parameter has an extra ? in its location #127373

@ValentinVignal

Description

@ValentinVignal

Is there an existing issue for this?

Related to

With the code generated by go_router_builder, when a route has an empty iterable (which can happen a lot when there is a default value), it always includes {} or [] in the query parameters which leads to a trailing ? at the end of the URL.
Is it possible to not include an empty iterable in the query parameters to avoid this behavior?

Steps to reproduce

  1. Run flutter run on the code sample given below
  2. Notice the print is /?

Expected results

I would expect the location to not have the extra ? if there are no parameters to specify

Actual results

The location ends with a ? and has not query parameters after.

Code sample

Code sample

You can also check out https://github.com/ValentinVignal/flutter_app_stable/tree/go-router-builder/extra-interrogation-mark-in-url

# main.dart

void main() {
  print(const MyRoute().location);
}
# pages.dart

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

part 'pages.g.dart';

@TypedGoRoute<MyRoute>(path: '/')
class MyRoute extends GoRouteData {
  const MyRoute({
    this.params = const [],
  });

  final List<int> params;

  @override
  Widget build(BuildContext context, GoRouterState state) {
    return const Placeholder();
  }
}

Screenshots or Video

No response

Logs

Logs
/?

Flutter Doctor output

Doctor output
[!] Flutter (Channel stable, 3.7.12, on macOS 13.3.1 22E772610a darwin-x64, locale en-GB)
    ! 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.
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.78.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

! Doctor found issues in 1 category.

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.11Found to occur in 3.11has 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