From 11c034f0371eb28576d41a0c218ccae6b38e7702 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Thu, 21 Mar 2024 16:38:16 -0700 Subject: [PATCH] Fix nullability of getFullHeightForCaret (#145554) Fixes https://github.com/flutter/flutter/issues/145507. Looks like this was accidentally migrated to nullable all the way back when we switched to NNBD. --- packages/flutter/lib/src/painting/text_painter.dart | 2 +- packages/flutter/lib/src/rendering/editable.dart | 2 +- packages/flutter/lib/src/rendering/paragraph.dart | 4 ++-- packages/flutter/test/painting/text_painter_test.dart | 2 +- packages/flutter/test/rendering/paragraph_test.dart | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/flutter/lib/src/painting/text_painter.dart b/packages/flutter/lib/src/painting/text_painter.dart index 356158a6c99..1993c04c68e 100644 --- a/packages/flutter/lib/src/painting/text_painter.dart +++ b/packages/flutter/lib/src/painting/text_painter.dart @@ -1352,7 +1352,7 @@ class TextPainter { /// {@endtemplate} /// /// Valid only after [layout] has been called. - double? getFullHeightForCaret(TextPosition position, Rect caretPrototype) { + double getFullHeightForCaret(TextPosition position, Rect caretPrototype) { final TextBox textBox = _getOrCreateLayoutTemplate().getBoxesForRange(0, 1, boxHeightStyle: ui.BoxHeightStyle.strut).single; return textBox.toRect().height; } diff --git a/packages/flutter/lib/src/rendering/editable.dart b/packages/flutter/lib/src/rendering/editable.dart index 71703cad4bd..52ab40b8ddb 100644 --- a/packages/flutter/lib/src/rendering/editable.dart +++ b/packages/flutter/lib/src/rendering/editable.dart @@ -1798,7 +1798,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin, switch (defaultTargetPlatform) { case TargetPlatform.iOS: case TargetPlatform.macOS: - final double fullHeight = _textPainter.getFullHeightForCaret(caretPosition, caretPrototype) ?? _textPainter.preferredLineHeight; + final double fullHeight = _textPainter.getFullHeightForCaret(caretPosition, caretPrototype); final double heightDiff = fullHeight - caretRect.height; // Center the caret vertically along the text. caretRect = Rect.fromLTWH( diff --git a/packages/flutter/lib/src/rendering/paragraph.dart b/packages/flutter/lib/src/rendering/paragraph.dart index b1ee1029408..42ca5655b6a 100644 --- a/packages/flutter/lib/src/rendering/paragraph.dart +++ b/packages/flutter/lib/src/rendering/paragraph.dart @@ -649,7 +649,7 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin