Repository: flutter
Issue: RenderParagraph reports wrong caret offset and height for inline widgets
Labels: framework,dependency: skia,has reproducible steps,P2,team-framework,triaged-framework,found in release: 3.24,found in release: 3.27

`RenderParagraph` has methods to calculate the offset and height for a caret at a given text position. Both of these values are wrong when sitting next to an inline widget.

**Repro:** 
See provided code.

**Expected results:**
The caret y-value and height is the same as any other text position on the same line.

**Actual results:**
The caret is placed at a different y-value, with a different height.

<img width="134" alt="Screenshot 2024-12-07 at 11 39 02 AM" src="https://github.com/user-attachments/assets/79bad8b9-df2b-460b-9a62-36a1240a223e">

**Code:**
<details><summary>Code</summary>
<pre><code>
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _textKey = GlobalKey();
  final _carets = <(Offset, double)>[];

  @override
  Widget build(BuildContext context) {
    final _textWithInlineWidget = TextSpan(
      text: 'a ',
      children: [
        WidgetSpan(
          alignment: PlaceholderAlignment.middle,
          child: Container(
            width: 24,
            height: 12,
            color: Colors.black,
          ),
        ),
        const TextSpan(text: ' c'),
      ],
    );

    if (_carets.isEmpty) {
      WidgetsBinding.instance.addPostFrameCallback((_) {
        setState(() {
          final renderParagraph =
              _textKey.currentContext!.findRenderObject() as RenderParagraph;

          for (int i = 0; i <= 4; i += 1) {
            _carets.add((
              renderParagraph.getOffsetForCaret(
                  TextPosition(
                      offset: i,
                      // We ust "upstream" to demonstrate that we can
                      // get the wrong caret height on both sides of
                      // the inline widget.
                      affinity: i == 3
                          ? TextAffinity.upstream
                          : TextAffinity.downstream),
                  Rect.zero),
              renderParagraph.getFullHeightForCaret(TextPosition(offset: i)),
            ));
          }
        });
      });
    }

    return Scaffold(
      body: Center(
        child: Stack(
          children: [
            Text.rich(
              _textWithInlineWidget,
              key: _textKey,
              style: const TextStyle(
                fontSize: 48,
              ),
            ),
            for (final caret in _carets) //
              Positioned(
                left: caret.$1.dx,
                top: caret.$1.dy,
                height: caret.$2,
                width: 4,
                child: const ColoredBox(color: Colors.blue),
              ),
          ],
        ),
      ),
    );
  }
}
</pre></code>
</details>