Repository: flutter
Issue: Wrong text height calculation when Text inside WidgetSpan
Labels: framework,has reproducible steps,P2,team-framework,triaged-framework,found in release: 3.19,found in release: 3.22

### Steps to reproduce

1) Create Rich text widget;
2) Put WidgetSpan inside rich text;
3) Put Text (text should wrap the line) widget inside Widget span
4) Put TextSpan with line break after WidgetSpan

May be it is important: Without step No. 4 or without line wrapping inside Text it works good.

### Expected results

Expected result 
![image](https://github.com/flutter/flutter/assets/14288495/59fd7a21-79d0-4cfb-a6b8-5b8c28f2caf1)


### Actual results

Unexpected space

![image](https://github.com/flutter/flutter/assets/14288495/bfaf7384-ea4a-4f96-904e-db4f7a582a0f)


### Code sample

<details open><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(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: ColoredBox(
            color: Colors.red,
            child: SizedBox(
              width: 300,
              child: Text.rich(
                TextSpan(
                  children: [
                    WidgetSpan(
                      child: Text(
                        'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
                      ),
                    ),
                    TextSpan(text: '\n'),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

```

</details>


### Screenshots or Video

_No response_

### Logs

_No response_

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.19.4, on macOS 14.1.1 23B81 darwin-arm64
    (Rosetta), locale en-AE)
    • Flutter version 3.19.4 on channel stable at
      /Users/boriskarabanov/fvm/versions/3.19.4
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 68bfaea224 (3 weeks ago), 2024-03-20 15:36:31 -0700
    • Engine revision a5c24f538d
    • Dart version 3.3.2
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/boriskarabanov/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Users/boriskarabanov/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 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Users/boriskarabanov/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)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
    • IntelliJ at /Users/boriskarabanov/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 76.3.4
    • Dart plugin version 232.10248

[✓] VS Code (version 1.88.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.86.0

[✓] Connected device (3 available)            
    • SM S9010 (mobile) • R5CT444XHFN • android-arm64  • Android 14 (API 34)
    • macOS (desktop)   • macos       • darwin-arm64   • macOS 14.1.1 23B81
      darwin-arm64 (Rosetta)
    • Chrome (web)      • chrome      • web-javascript • Google Chrome
      123.0.6312.107
    ! Error: Browsing on the local area network for Boris Karabanov’s iPhone.
      Ensure the device is unlocked and attached with a cable or associated with
      the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code
      -27)

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>