Repository: flutter
Issue: NestedScrollView's body prompt overflow error
Labels: framework,f: scrolling,has reproducible steps,P2,found in release: 3.10,found in release: 3.12,team-framework,triaged-framework

### 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 sample code
2. scroll and switch to 'outerTab2'

https://github.com/flutter/flutter/assets/35989475/db20918e-b29a-4e20-a5e5-7408cd5bf929

### Expected results

I would think that the NestedScrollView's body is already inside the scrolling widget and should not overflow.

### Actual results

Prompt overflow error

### Code sample

<details><summary>Code sample</summary>

```dart
void main() => runApp(NestedScrollViewExampleApp());

class NestedScrollViewExampleApp extends StatelessWidget {
  const NestedScrollViewExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Demo(),
    );
  }
}

class Demo extends StatefulWidget {
  const Demo({Key? key}) : super(key: key);

  @override
  State<Demo> createState() => _DemoState();
}

class _DemoState extends State<Demo> with TickerProviderStateMixin {
  List<String> outerTabs = ['outerTab1', 'outerTab2'];

  TabController? _tabController;

  @override
  void initState() {
    super.initState();
    _tabController =
        TabController(initialIndex: 0, length: outerTabs.length, vsync: this);
  }

  @override
  void dispose() {
    _tabController?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            SliverAppBar(
              title: const Text('Demo'),
              floating: true,
              snap: true,
              expandedHeight: 200,
              forceElevated: innerBoxIsScrolled,
              flexibleSpace: const FlexibleSpaceBar(
                background: Placeholder(
                  fallbackHeight: 300,
                ),
              ),
            ),
            SliverToBoxAdapter(
              child: Container(
                height: 300,
                color: Colors.amber,
              ),
            ),
            SliverToBoxAdapter(
              child: Container(
                height: 200,
                color: Colors.cyan,
              ),
            ),
            SliverToBoxAdapter(
              child: TabBar(
                labelColor: Colors.black,
                controller: _tabController,
                tabs: outerTabs
                    .map((e) => Tab(
                          text: e,
                        ))
                    .toList(),
              ),
            )
          ];
        },
        body: TabBarView(
          controller: _tabController,
          children: const [
            Tab1(),
            Tab2(),
          ],
        ),
      ),
    );
  }
}

class Tab1 extends StatelessWidget {
  const Tab1({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemBuilder: (context, index) {
        return ListTile(title: Text('$index'));
      },
      itemCount: 50,
    );
  }
}

class Tab2 extends StatefulWidget {
  const Tab2({Key? key}) : super(key: key);

  @override
  State<Tab2> createState() => _Tab2State();
}

class _Tab2State extends State<Tab2> with TickerProviderStateMixin {
  PageController? _pageController;
  TabController? _tabController;

  List<String> tabs = ['nestTab1', 'nestTab2'];

  @override
  void initState() {
    super.initState();
    _tabController =
        TabController(initialIndex: 0, length: tabs.length, vsync: this);
    _pageController = PageController(initialPage: 0);
  }

  @override
  void dispose() {
    _tabController?.dispose();
    _pageController?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        TabBar(
          labelColor: Colors.black,
            controller: _tabController,
            onTap: (index) {
              _pageController?.jumpToPage(index);
            },
            tabs: tabs
                .map<Widget>((item) => Tab(
                      text: item,
                    ))
                .toList(),
            isScrollable: true),
        Expanded(
          child: PageView.builder(
            itemCount: tabs.length,
            controller: _pageController,
            onPageChanged: (index) {
              _tabController?.animateTo(index);
            },
            itemBuilder: (context, index) => ListView.builder(
              itemBuilder: (context, index) {
                return ListTile(title: Text('$index'));
              },
              itemCount: 50,
            ),
          ),
        ),
      ],
    );
  }
}
```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

https://github.com/flutter/flutter/assets/35989475/db20918e-b29a-4e20-a5e5-7408cd5bf929

</details>


### Logs

<details><summary>Logs</summary>

```console
======== Exception caught by rendering library =====================================================
The following assertion was thrown during layout:
A RenderFlex overflowed by 21 pixels on the bottom.

The relevant error-causing widget was: 
  Column Column:file:///Users/yangjiakang/Code/flutter_example/lib/main.dart:140:12
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.

Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.

The specific RenderFlex in question is: RenderFlex#6d68f OVERFLOWING
...  needs compositing
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(w=360.0, h=27.0)
...  size: Size(360.0, 27.0)
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: center
...  verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
====================================================================================================
```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[!] Flutter (Channel unknown, 3.11.0-2.0.pre.51, on macOS 13.0.1 22A400
    darwin-arm64, locale zh-Hans-CN)
    ! Flutter version 3.11.0-2.0.pre.51 on channel unknown at
      /Users/yangjiakang/flutter/framework
      Currently on an unknown channel. Run `flutter channel` to switch to an
      official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions
      at https://flutter.dev/docs/get-started/install.
    ! Unknown upstream repository.
      Reinstall Flutter by following instructions at
      https://flutter.dev/docs/get-started/install.
    • Framework revision 7c356d047d (7 周前), 2023-05-06 12:22:11 +0800
    • Engine revision 876968833e
    • Dart version 3.1.0 (build 3.1.0-82.0.dev)
    • 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.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/yangjiakang/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • ANDROID_HOME = /Users/yangjiakang/Library/Android/sdk
    • ANDROID_SDK_ROOT = /Users/yangjiakang/Library/Android/sdk
    • Java binary at: /Applications/Android
      Studio.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)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio
    • Android Studio at /Applications/Android Studio Preview.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.4.1+0-17.0.4.1b469.62-9127311)

[✓] Android Studio (version 2022.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
      11.0.15+0-b2043.56-8887301)

[✓] Android Studio
    • Android Studio at
      /Users/yangjiakang/Code/androidx/studio/android-studio-2022.2.1.7-mac_arm/
      Android Studio Preview.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.4.1+0-17.0.4.1b469.62-9127311)

[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.2)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • 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

[✓] VS Code (version 1.79.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.66.0

[!] Proxy Configuration
    • HTTP_PROXY is set
    • NO_PROXY is localhost,127.0.0.1
    • NO_PROXY contains localhost
    • NO_PROXY contains 127.0.0.1
    ! NO_PROXY does not contain ::1

[✓] Connected device (4 available)
    • PERM00 (mobile)            • XOCAQ87LIR597TEA                     •
      android-arm64  • Android 12 (API 31)
    • iPhone 14 Pro Max (mobile) • DFEB59A1-1EBF-4E49-8340-B1F5522690A6 • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)            • macos                                •
      darwin-arm64   • macOS 13.0.1 22A400 darwin-arm64
    • Chrome (web)               • chrome                               •
      web-javascript • Google Chrome 114.0.5735.133

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.
```

</details>