Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[go_router] Path and query parameters are not preserved in StatefulShellRoute #129878

Closed
2 tasks done
MicTheFox opened this issue Jul 1, 2023 · 19 comments · Fixed by flutter/packages#6698
Closed
2 tasks done
Assignees
Labels
found in release: 3.10 Found to occur in 3.10 found in release: 3.12 Found to occur in 3.12 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: go_router The go_router package P1 High-priority issues at the top of the work list package flutter/packages repository. See also p: labels. r: fixed Issue is closed as already fixed in a newer version team-go_router Owned by Go Router team triaged-go_router Triaged by Go Router team

Comments

@MicTheFox
Copy link

Is there an existing issue for this?

Steps to reproduce

The sample code provided is a variation of the StatefulShellRoute example. In this example the StatefulShellRoute is a SubRoute of the route /list/:id which contains the path parameter :id. The :id parameter is initially set correctly, but is not preserved after calling goBranch(). The same behaviour happens to queryParameters (not implemented in the provided sample code).

  1. Run the code sample
  2. Tap "Section B"

Expected results

The "id" parameter should stay the same as before.

Actual results

The "id" parameter actually has the value ":id".

Code sample

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

void main() {
  runApp(NestedTabNavigationExampleApp());
}

class NestedTabNavigationExampleApp extends StatelessWidget {
  NestedTabNavigationExampleApp({super.key});

  final GoRouter _router = GoRouter(
    initialLocation: '/list/123/a',
    routes: <RouteBase>[
      GoRoute(
        path: '/list',
        builder: (_, __) => const Placeholder(),
        routes: [
          GoRoute(
            path: ':id',
            builder: (_, __) => const Placeholder(),
            routes: [
              StatefulShellRoute.indexedStack(
                builder: (BuildContext context, GoRouterState state,
                    StatefulNavigationShell navigationShell) {
                  return ScaffoldWithNavBar(navigationShell: navigationShell);
                },
                branches: <StatefulShellBranch>[
                  StatefulShellBranch(
                    routes: <RouteBase>[
                      GoRoute(
                        path: 'a',
                        builder: (BuildContext context, GoRouterState state) =>
                            RootScreen(
                          label: 'A',
                          id: state.pathParameters['id']!,
                        ),
                      ),
                    ],
                  ),
                  StatefulShellBranch(
                    routes: <RouteBase>[
                      GoRoute(
                        path: 'b',
                        builder: (BuildContext context, GoRouterState state) =>
                            RootScreen(
                          label: 'B',
                          id: state.pathParameters['id']!,
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
    ],
  );

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      routerConfig: _router,
    );
  }
}

class ScaffoldWithNavBar extends StatelessWidget {
  const ScaffoldWithNavBar({
    required this.navigationShell,
    Key? key,
  }) : super(key: key ?? const ValueKey<String>('ScaffoldWithNavBar'));

  final StatefulNavigationShell navigationShell;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: navigationShell,
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Section A'),
          BottomNavigationBarItem(icon: Icon(Icons.work), label: 'Section B'),
        ],
        currentIndex: navigationShell.currentIndex,
        onTap: (int index) => _onTap(context, index),
      ),
    );
  }

  void _onTap(BuildContext context, int index) {
    navigationShell.goBranch(
      index,
      initialLocation: index == navigationShell.currentIndex,
    );
  }
}

class RootScreen extends StatelessWidget {
  const RootScreen({
    required this.label,
    required this.id,
    super.key,
  });

  final String label;
  final String id;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Root of section $label'),
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text('Screen $label',
                style: Theme.of(context).textTheme.titleLarge),
            const Padding(padding: EdgeInsets.all(4)),
            Text('Id: $id'),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration
Simulator.Screen.Recording.-.iPhone.14.Pro.Max.-.2023-07-01.at.20.12.16.mp4

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.10.5, on macOS 13.4.1 22F82 darwin-arm64, locale en-GB)
    • Flutter version 3.10.5 on channel stable at /Users/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (3 weeks ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Platform android-33, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio ARM.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • 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.0

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio ARM.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.15+0-b2043.56-8887301)

[✓] Android Studio (version 2021.1)
    • Android Studio at/Applications/Android Studio ARM.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-7772763)

[✓] Connected device (3 available)
    • iPhone 14 Pro Max (mobile) • 500A390D-6B90-4F0A-BD61-422F3955A22F • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 13.4.1 22F82 darwin-arm64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 114.0.5735.198

[✓] Network resources
    • All expected network resources are available.
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Jul 3, 2023
@darshankawar
Copy link
Member

Thanks for the report @MicTheFox
Can you take a look at this issue and see if it resembles your case or not ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 3, 2023
@MicTheFox
Copy link
Author

Thanks for the report @MicTheFox Can you take a look at this issue and see if it resembles your case or not ?

@darshankawar Looks similar, but the bug here occurs without using any redirect. I don't know how goBranch() works under the hood, but if it is using any kind of redirect, then those two issues might be related.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 3, 2023
@darshankawar
Copy link
Member

Thanks for the update. Using the original repo code, seeing the same behavior as reported. Maybe related to #123973

stable, master flutter doctor -v
[!] Flutter (Channel stable, 3.10.5, on macOS 12.2.1 21D62 darwin-x64, locale
    en-GB)
    • Flutter version 3.10.5 on channel stable at
      /Users/dhs/documents/fluttersdk/flutter
    ! Warning: `flutter` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
      your current Flutter SDK checkout at
      /Users/dhs/documents/fluttersdk/flutter. Consider adding
      /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
      Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
      of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (2 days ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.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.

[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

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

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

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

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

! Doctor found issues in 1 category.

[!] Flutter (Channel master, 3.12.0-13.0.pre.38, on macOS 12.2.1 21D62
    darwin-x64, locale en-GB)
    • Flutter version 3.12.0-13.0.pre.38 on channel master at
      /Users/dhs/documents/fluttersdk/flutter
    ! Warning: `flutter` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
      your current Flutter SDK checkout at
      /Users/dhs/documents/fluttersdk/flutter. Consider adding
      /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
      Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
      of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 9760bb0cf0 (3 hours ago), 2023-07-03 13:54:18 +1200
    • Engine revision e6b8292705
    • Dart version 3.1.0 (build 3.1.0-262.0.dev)
    • DevTools version 2.25.0
    • 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 /Users/dhs/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for
      more details.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 13C100
    • CocoaPods version 1.11.2

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

[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 65.1.4
    • Dart plugin version 213.7228

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

[✓] Connected device (3 available)
    • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios
      • iOS 15.3.1 19D52
    • macOS (desktop)           • macos                                    •
      darwin-x64     • macOS 12.2.1 21D62 darwin-x64
    • Chrome (web)              • chrome                                   •
      web-javascript • Google Chrome 109.0.5414.119

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

! Doctor found issues in 1 category.
      
[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

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

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

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

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

! Doctor found issues in 1 category.



@darshankawar darshankawar added package flutter/packages repository. See also p: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on p: go_router The go_router package found in release: 3.10 Found to occur in 3.10 found in release: 3.12 Found to occur in 3.12 and removed in triage Presently being triaged by the triage team labels Jul 3, 2023
@stuartmorgan stuartmorgan added the P2 Important issues not at the top of the work list label Jul 6, 2023
@chunhtai chunhtai added team-go_router Owned by Go Router team triaged-go_router Triaged by Go Router team labels Jul 6, 2023
@Hixie Hixie removed the triaged-go_router Triaged by Go Router team label Jul 8, 2023
@chunhtai chunhtai added triaged-go_router Triaged by Go Router team P1 High-priority issues at the top of the work list and removed P2 Important issues not at the top of the work list labels Jul 13, 2023
@Sten435
Copy link

Sten435 commented Aug 11, 2023

How can this issue not been fixed already after 1 month ? Its like a core thing lol

@flutter-triage-bot flutter-triage-bot bot removed the triaged-go_router Triaged by Go Router team label Dec 3, 2023
@flutter-triage-bot
Copy link

This issue is marked P1 but has had no recent status updates.

The P1 label indicates high-priority issues that are at the top of the work list. This is the highest priority level a bug can have if it isn't affecting a top-tier customer or breaking the build. Bugs marked P1 are generally actively being worked on unless the assignee is dealing with a P0 bug (or another P1 bug). Issues at this level should be resolved in a matter of months and should have monthly updates on GitHub.

Please consider where this bug really falls in our current priorities, and label it or assign it accordingly. This allows people to have a clearer picture of what work is actually planned. Thanks!

@d-polikhranidi
Copy link

d-polikhranidi commented Dec 7, 2023

same behavior with go_router 12.1.1 and there's still no fix

@chunhtai chunhtai added the triaged-go_router Triaged by Go Router team label Dec 7, 2023
@chunhtai
Copy link
Contributor

chunhtai commented Dec 7, 2023

this is serious bug, but this should wait for the flutter/packages#5497 to land.

@firgia
Copy link

firgia commented Jan 25, 2024

I hope the team can fix it ASAP.

I got this issue when I used a 'redirect'. To fix this issue, I just updated the path from 'redirect' and added custom path parameters and works like a charm.

GoRouter(
    routes: [
      GoRoute(
        path: "/email-verified/:email",
        name: RouteName.emailVerified,
        pageBuilder: (context, state) {
          String email = state.pathParameters["email"] ?? "-";
          return CupertinoPage(
            child: EmailVerifiedScreen(
              email: email,
            ),
            fullscreenDialog: true,
          );
        },
      ),
    ],
    redirect: (context, state) {
      String? fullPath = state.fullPath;

      /* UPDATE PATH */
      if (fullPath == "/email-verified/:email") {
        return "/email-verified/${state.pathParameters['email']}";
      }

      return fullPath;
    },
  )

@Uirado
Copy link

Uirado commented Feb 16, 2024

Any updates on this issue?

@bes89
Copy link

bes89 commented Feb 16, 2024

@Uirado did you update go router? For us it was fixed with the update to newest version

@Uirado
Copy link

Uirado commented Feb 18, 2024

@bes89 Yes. I tested using version 13.2.0 and this bug is still happening.

@taylanyildiz
Copy link

taylanyildiz commented Feb 25, 2024

Hi, Is there any solution for this

  • Page Detail
    path: ':id'
    • StatefulShellRoute ( Sub route )
      branches:
      • ShellBranch
        path: 'properties'
      • ShellBranch
        path: 'notes'

Then when I used the goBranch(index) path parameters returns named like ":id". Same issue issue#137823 I think

@brunodmn
Copy link

I have the same problem...Thought I might have done something wrong.

I am struggling to create a deeply nested typed navigation with TypedStatefulShellRoute, I have a sidebar menu that navigates to a route that has tabs. Documentation is not quite helping me.

@TypedStatefulShellRoute<HomeShellRoute>(
  branches: [
    TypedStatefulShellBranch<HomeBranch>(
      routes: <TypedGoRoute<GoRouteData>>[
        TypedGoRoute<HomeRoute>(path: '/home'),
      ],
    ),
   (...),
    TypedStatefulShellBranch<AppsBranch>(
      routes: <TypedGoRoute<GoRouteData>>[
        TypedGoRoute<AppsRoute>(path: '/apps', routes: [
          TypedGoRoute<AppRoute>(path: ':id', routes: [
            TypedStatefulShellRoute<AppShellRoute>(branches: [
              TypedStatefulShellBranch<AppGeneralBranch>(
                  routes: [TypedGoRoute<AppGeneralRoute>(path: 'general')]),
              TypedStatefulShellBranch<AppSupporBranch>(
                  routes: [TypedGoRoute<AppSupportRoute>(path: 'support')]),
            ])
          ]),
        ]),
      ],
    ),
  ],
)

ezgif-3-cd1f8f8708

@P1Rh0
Copy link

P1Rh0 commented May 8, 2024

Is there any movement on this P1? My BottomDrawer navigation is just broken without it :( is there anything we can do to help?

@chunhtai chunhtai self-assigned this May 8, 2024
@chunhtai
Copy link
Contributor

chunhtai commented May 8, 2024

I forgot to follow up on this

@chunhtai
Copy link
Contributor

chunhtai commented May 8, 2024

The missing path parameters are indeed considered a bug

I am not sure whether the query parameter should carry over by default, what happen if gobranch goes to a branch that has existing state? do we replace it or not?

@P1Rh0
Copy link

P1Rh0 commented May 8, 2024

I think I'd probably expect the query parameters not to be passed across multiple routes but would, perhaps, expect to be able to add them optionally via gobranch?
I've not used query parameters myself so happy to bow to anyone who has

@P1Rh0
Copy link

P1Rh0 commented May 18, 2024

Just updated and everything looks good to me! Thanks for jumping on this quickly, it's appreciated :)

@darshankawar darshankawar added the r: fixed Issue is closed as already fixed in a newer version label May 20, 2024
@brunodmn
Copy link

@chunhtai Thank you for your effort and quick reply.

Unfortunately, on my environment, the path parameter is not changing anymore, but nested shell index seems not to change either, which makes my nested navigation stop working.

I did not change any code, just updated dependency go_router to 14.1.2 and dev_dependency go_router_builder to 2.7.0. I ran flutter pub run build_runner build after the update and it did not make any changes on my routes.g.dart file.

ScreenRecording2024-05-20at09 53 54-ezgif com-video-to-gif-converter

Its not quite visible on the image, but navigationShell.currentIndex stays on 0, before the updat my onTap event would change it (0 first tab, 1 second tab).

TecHaxter pushed a commit to TecHaxter/flutter_packages that referenced this issue May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
found in release: 3.10 Found to occur in 3.10 found in release: 3.12 Found to occur in 3.12 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: go_router The go_router package P1 High-priority issues at the top of the work list package flutter/packages repository. See also p: labels. r: fixed Issue is closed as already fixed in a newer version team-go_router Owned by Go Router team triaged-go_router Triaged by Go Router team
Projects
None yet
Development

Successfully merging a pull request may close this issue.