Repository: flutter
Issue: Calling go after pop using GoRouter with a StatefulShellRoute breaks navigation
Labels: package,has reproducible steps,P2,p: go_router,team-go_router,triaged-go_router,found in release: 3.24,found in release: 3.27

### Steps to reproduce

1. Use provided sample code
2. Launch App
3. Tap on "Page B"
4. Tap on "Details…" button
5. Tab on "Home" button
6. Tab on "Page B"
7. Tab on "Details…" button

### Expected results

I would expect the details page to appear again after step 7.

### Actual results

No navigation occurs. The app stays on "Page B".

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

void main() {
  runApp(const MyApp());
}

final GoRouter routerConfig = GoRouter(
  initialLocation: '/a',
  debugLogDiagnostics: true,
  routes: [
    StatefulShellRoute.indexedStack(
      builder: (_, __, StatefulNavigationShell navigationShell) =>
          HomePage(navigationShell: navigationShell),
      branches: [
        StatefulShellBranch(
          routes: [
            GoRoute(
              path: '/a',
              builder: (context, state) => const PageA(),
            )
          ],
        ),
        StatefulShellBranch(
          routes: [
            GoRoute(
              path: '/b',
              builder: (context, state) => const PageB(),
              routes: [
                GoRoute(
                  path: 'detail',
                  builder: (context, state) => const DetailPage(),
                )
              ],
            ),
          ],
        ),
      ],
    )
  ],
);

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Test',
      routerConfig: routerConfig,
    );
  }
}

class HomePage extends StatelessWidget {
  final StatefulNavigationShell navigationShell;

  const HomePage({
    super.key,
    required this.navigationShell,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: navigationShell,
      bottomNavigationBar: BottomNavigationBar(
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Page A'),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Page B'),
        ],
        onTap: (value) {
          navigationShell.goBranch(value);
        },
        currentIndex: navigationShell.currentIndex,
      ),
    );
  }
}

class PageA extends StatelessWidget {
  const PageA({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Page A'),
      ),
      body: const Center(
        child: Text('…'),
      ),
    );
  }
}

class PageB extends StatelessWidget {
  const PageB({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Page B'),
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            const Text('…'),
            ElevatedButton(
              child: const Text('Details…'),
              onPressed: () {
                GoRouter.of(context).go('/b/detail');
              },
            )
          ],
        ),
      ),
    );
  }
}

class DetailPage extends StatelessWidget {
  const DetailPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Detail'),
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            const Text('…'),
            ElevatedButton(
              child: const Text('Home'),
              onPressed: () {
                final router = GoRouter.of(context);
                router.pop();
                router.go('/a');
              },
            )
          ],
        ),
      ),
    );
  }
}
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
[GoRouter] Full paths for routes:
           └─ (ShellRoute)
             ├─/a (PageA)
             └─/b (PageB)
               └─/b/detail (DetailPage)
[GoRouter] setting initial location /a
2
[GoRouter] Using MaterialApp configuration
D/EGL_emulation(18322): app_time_stats: avg=252.32ms min=11.35ms max=8030.31ms count=34
D/EGL_emulation(18322): app_time_stats: avg=1745.91ms min=1745.91ms max=1745.91ms count=1
[GoRouter] going to /b
[GoRouter] Using MaterialApp configuration
D/EGL_emulation(18322): app_time_stats: avg=28.74ms min=7.09ms max=403.04ms count=35
[GoRouter] going to /b/detail
W/WindowOnBackDispatcher(18322): OnBackInvokedCallback is not enabled for the application.
W/WindowOnBackDispatcher(18322): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest.
D/EGL_emulation(18322): app_time_stats: avg=50.57ms min=5.31ms max=850.70ms count=25
[GoRouter] popping /b/detail
[GoRouter] going to /a
D/EGL_emulation(18322): app_time_stats: avg=58.27ms min=7.41ms max=848.80ms count=20
[GoRouter] restoring /b/detail
D/EGL_emulation(18322): app_time_stats: avg=31.18ms min=12.00ms max=582.96ms count=39
[GoRouter] going to /b/detail
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.24.0, on macOS 15.1 24B83 darwin-arm64, locale en-US)
    • Flutter version 3.24.0 on channel stable at /Users/dirkmika/projects/SDKs/Flutter/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 80c2e84975 (3 months ago), 2024-07-30 23:06:49 +0700
    • Engine revision b8800d88be
    • Dart version 3.5.0
    • DevTools version 2.37.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/dirkmika/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16A242d
    • CocoaPods version 1.15.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2023.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 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.95.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.98.0

[✓] Connected device (5 available)
    • sdk gphone64 arm64 (mobile)     • emulator-5554                        • android-arm64 • Android 14 (API 34) (emulator)
    • Mein 13 Pro (mobile)            • 00008110-000A34300C62801E            • ios           • iOS 18.1 22B83
    • iPhone 15 Pro (mobile)          • ED1976BA-F0CC-4A90-BE74-25A9E49D110D • ios           • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64  • macOS 15.1 24B83 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin        • macOS 15.1 24B83 darwin-arm64

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.
```

</details>