Repository: flutter
Issue: RenderFlex overflow when using SegmentedButton in CustomScrollView
Labels: framework,f: material design,a: error message,has reproducible steps,P2,workaround available,found in release: 3.10,found in release: 3.11,team-design,triaged-design

### 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. Create a new project
2. Write the provided code sample
3. Run it (in my case, for web)
4. Decrease the window size so the text in the ButtonSegment must be split into two or more lines.
5. See the overflow error at the bottom

### Expected results

The text should be split in multiple lines if necessary without throwing any overflow errors the same way other widgets do.
The expected behaviour can be seen replacing the SegmentedButton for any widget with contents that must be split into multiple lines with reduced width windows like an ElevatedButton:
```Dart
ElevatedButton(
  onPressed: () {},
  child: const Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec euismod, nisl eget ultricies ultricies, nisl ni"),
)
```


### Actual results

An exception is thrown when the screen width is small, so the text in the ButtonSegment must be split into two or more lines:
```bash
======== Exception caught by rendering library =====================================================
The following assertion was thrown during layout:
A RenderFlex overflowed by 4.0 pixels on the bottom.

The relevant error-causing widget was: 
  Column Column:file:///K:/GitHub/cabron/lib/main.dart:34:20
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#45c07 OVERFLOWING
...  parentData: paintOffset=Offset(0.0, -177.1)
...  constraints: BoxConstraints(w=767.2, h=911.2)
...  size: Size(767.2, 911.2)
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: center
...  verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
====================================================================================================
```

### Code sample

<details><summary>Code sample</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 const MaterialApp(
      title: 'Issue with SegmentedButton',
      home: DemoPage(),
    );
  }
}

enum Options {
  a,
  b,
}

class DemoPage extends StatelessWidget {
  const DemoPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          SliverFillRemaining(
            hasScrollBody: false,
            child: Column(
              children: [
                SegmentedButton(segments: const [
                  ButtonSegment<Options>(value: Options.a, label: Text("Any text that will be 2 or more lines when the width is too small to fit in a single line")),
                  ButtonSegment<Options>(value: Options.b, label: Text("Any text that will be 2 or more lines when the width is too small to fit in a single line")),
                ], selected: const <Options>{
                  Options.a
                }, onSelectionChanged: (newSelection) {}),
                // SizedBox used to force scrollable column
                SizedBox(height: MediaQuery.of(context).size.height * 1.2, child: const Placeholder()),
              ],
            ),
          )
        ],
      ),
    );
  }
}
```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

With error (multiple lines of text):

![image](https://github.com/flutter/flutter/assets/11029629/1b8b632b-ecbc-40e2-931c-a105b502d4ad)

Without error (text in single line):

![image](https://github.com/flutter/flutter/assets/11029629/20463af8-9800-401d-ad14-3c56a44866a2)

</details>


### Logs

_No response_

### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.7.10, on Microsoft Windows [Version 10.0.22621.1702], locale en-150)
    • Flutter version 3.7.10 on channel stable at K:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4b12645012 (6 weeks ago), 2023-04-03 17:46:48 -0700
    • Engine revision ec975089ac
    • Dart version 2.19.6
    • DevTools version 2.20.1

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at C:\Users\guple\AppData\Local\Android\Sdk
    • Platform android-33-ext4, build-tools 33.0.1
    • ANDROID_HOME = C:\Users\guple\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.19)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
    • Visual Studio Build Tools 2019 version 16.11.32901.82
    • Windows 10 SDK version 10.0.19041.0

[✓] Android Studio (version 2022.1)
    • 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 11.0.15+0-b2043.56-9505619)

[✓] VS Code (version 1.76.2)
    • VS Code at C:\Users\guple\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.60.0

[✓] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.1702]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 113.0.5672.93
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 113.0.1774.42

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
```

</details>