Repository: flutter
Issue: [go_router] Combining ShellRoute and NestedScrollView
Labels: framework,f: scrolling,package,has reproducible steps,P3,p: go_router,team-framework,triaged-framework,found in release: 3.13,found in release: 3.17

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

1. Run the code sample

### Expected results

When scrolling up, the app bar should shrink because it is wrapped in a NestedScrollView (see video without go_router).

### Actual results

The app bar stays where it is and the custom scroll view scrolls under it.

### Code sample

<details><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: _router,
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
    );
  }
}

// GoRouter configuration
final _router = GoRouter(
  initialLocation: "/home",
  routes: [
    ShellRoute(
      builder: (context, state, child) {
        return ShellRoutePage(child: child);
      },
      routes: [
        GoRoute(
          path: "/home",
          builder: (context, state) {
            return MyHomePage();
          },
        ),
      ],
    ),
  ],
);

class ShellRoutePage extends StatelessWidget {
  final Widget child;

  const ShellRoutePage({super.key, required this.child});

  @override
  Widget build(BuildContext context) {
    return NestedScrollView(
      headerSliverBuilder: (context, innerBoxIsScrolled) {
        return [
          const SliverAppBar(
            pinned: true,
            expandedHeight: 200,
            flexibleSpace: FlexibleSpaceBar(
              background: ColoredBox(
                color: Colors.yellow,
              ),
            ),
          )
        ];
      },
      body: child,
    );
  }
}

class MyHomePage extends StatelessWidget {
  final List<Color> _colors = [Colors.red, Colors.blue, Colors.green];

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: [
        SliverList.builder(
          itemBuilder: (context, index) {
            return Container(
              height: 100,
              color: _colors[index % _colors.length],
            );
          },
        )
      ],
    );
  }
}
```

</details>

<details><summary>Working code sample (without go_router)</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final List<Color> _colors = [Colors.red, Colors.blue, Colors.green];

  @override
  Widget build(BuildContext context) {
    return NestedScrollView(
      headerSliverBuilder: (context, innerBoxIsScrolled) {
        return [
          const SliverAppBar(
            pinned: true,
            expandedHeight: 200,
            flexibleSpace: FlexibleSpaceBar(
              background: ColoredBox(
                color: Colors.yellow,
                child: Center(child: Text("without go_router")),
              ),
            ),
          )
        ];
      },
      body: CustomScrollView(
        slivers: [
          SliverList.builder(
            itemBuilder: (context, index) {
              return Container(
                height: 100,
                color: _colors[index % _colors.length],
              );
            },
          )
        ],
      ),
    );
  }
}

}
```

</details>



### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

With go_router:

[with_go_router.webm](https://github.com/flutter/flutter/assets/46818679/01e4d1b4-f120-4314-aa6b-9b1a9ca02976)

Without go_router (expected results):

[without_go_router.webm](https://github.com/flutter/flutter/assets/46818679/84e24360-79fc-411f-9341-b89e1d56f333)

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[√] Flutter (Channel stable, 3.13.2, on Microsoft Windows [Version 10.0.22621.2428], locale de-DE)
    • Flutter version 3.13.2 on channel stable at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ff5b5b5fa6 (3 months ago), 2023-08-24 08:12:28 -0500
    • Engine revision b20183e040
    • Dart version 3.1.0
    • DevTools version 2.25.0

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\TimBa\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.27)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
    • Visual Studio Build Tools 2019 version 16.11.33801.447
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2022.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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.6+0-b2043.56-9586694)

[√] VS Code (version 1.84.1)
    • VS Code at C:\Users\TimBa\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 14 (API 34) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22621.2428]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 119.0.6045.123
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 119.0.2151.44

[√] Network resources
    • All expected network resources are available.

• No issues found!

```

</details>