Skip to content

[go_router] Preserve route name case when caching _nameToPath #127016

@Khalidm98

Description

@Khalidm98

Is there an existing issue for this?

Steps to reproduce

  1. implement multiple screens (I have more than 50) that will be linked to routes
  2. configure routes with path, name, and builder params
  3. run flutter build apk --obfuscate --split-debug-info=build/app/outputs/split-debug-info

Expected results

App should be working fine as it does in development, all named routes should be linked to its configured paths

Actual results

named routes overwrite each other; since I use --obfuscate when generating the apk, and use the (Screen).toString() as route name. Code obfuscation alters the class names, making 2 routes have the same name but in different case.
I checked the following:
(Login).toString() = uwb
(Register).toString() = Uwb

RouteConfiguration.namedLocation() includes this logic:

...
final String keyName = name.toLowerCase();
assert(_nameToPath.containsKey(keyName), 'unknown route name: $name');
...

RouteConfiguration._cacheNameToPath() includes this logic:

if (route.name != null) {
  final String name = route.name!.toLowerCase();
  assert(
      !_nameToPath.containsKey(name),
      'duplication fullpaths for name '
      '"$name":${_nameToPath[name]}, $fullPath');
  _nameToPath[name] = fullPath;
}

This makes the router navigate to Login screen whether I use context.goNamed((Login).toString()) or context.goNamed((Register).toString())

I could change the way I am naming my routes, but the way I do it makes it easier for development; so if I refactor the screen name, it will be changed in all places, also it doesn't require me to remember every name for every route, or force me to add an extra name to screen mapper.

I couldn't find any use case for using name.toLoweCase() neither in the docs nor in the package code, I think removing toLowerCase() in these 2 places will fix the issue and will not affect the logic anyhow.

Code sample

final router = GoRouter(
  routes: [
    GoRoute(
      path: '/login',
      name: (Login).toString(),
      builder: (_, __) => Login(),
    ),
    GoRoute(
      path: '/register',
      name: (Register).toString(),
      builder: (_, __) => Register(),
    ),
    ...
  ],
);

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

[✓] Flutter (Channel stable, 3.3.3, on macOS 13.3.1 22E261 darwin-arm, locale en-EG)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: go_routerThe go_router 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