Skip to content

Commit 11c034f

Browse files
authored
Fix nullability of getFullHeightForCaret (#145554)
Fixes flutter/flutter#145507. Looks like this was accidentally migrated to nullable all the way back when we switched to NNBD.
1 parent 3b390c5 commit 11c034f

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

packages/flutter/lib/src/painting/text_painter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ class TextPainter {
13521352
/// {@endtemplate}
13531353
///
13541354
/// Valid only after [layout] has been called.
1355-
double? getFullHeightForCaret(TextPosition position, Rect caretPrototype) {
1355+
double getFullHeightForCaret(TextPosition position, Rect caretPrototype) {
13561356
final TextBox textBox = _getOrCreateLayoutTemplate().getBoxesForRange(0, 1, boxHeightStyle: ui.BoxHeightStyle.strut).single;
13571357
return textBox.toRect().height;
13581358
}

packages/flutter/lib/src/rendering/editable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
17981798
switch (defaultTargetPlatform) {
17991799
case TargetPlatform.iOS:
18001800
case TargetPlatform.macOS:
1801-
final double fullHeight = _textPainter.getFullHeightForCaret(caretPosition, caretPrototype) ?? _textPainter.preferredLineHeight;
1801+
final double fullHeight = _textPainter.getFullHeightForCaret(caretPosition, caretPrototype);
18021802
final double heightDiff = fullHeight - caretRect.height;
18031803
// Center the caret vertically along the text.
18041804
caretRect = Rect.fromLTWH(

packages/flutter/lib/src/rendering/paragraph.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin<RenderBo
649649
}
650650

651651
Offset _getOffsetForPosition(TextPosition position) {
652-
return getOffsetForCaret(position, Rect.zero) + Offset(0, getFullHeightForCaret(position) ?? 0.0);
652+
return getOffsetForCaret(position, Rect.zero) + Offset(0, getFullHeightForCaret(position));
653653
}
654654

655655
@override
@@ -952,7 +952,7 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin<RenderBo
952952
/// {@macro flutter.painting.textPainter.getFullHeightForCaret}
953953
///
954954
/// Valid only after [layout].
955-
double? getFullHeightForCaret(TextPosition position) {
955+
double getFullHeightForCaret(TextPosition position) {
956956
assert(!debugNeedsLayout);
957957
_layoutTextWithConstraints(constraints);
958958
return _textPainter.getFullHeightForCaret(position, Rect.zero);

packages/flutter/test/painting/text_painter_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ void main() {
380380
final double caretHeight = painter.getFullHeightForCaret(
381381
const ui.TextPosition(offset: 0),
382382
ui.Rect.zero,
383-
)!;
383+
);
384384
expect(caretHeight, 50.0);
385385
painter.dispose();
386386
}, skip: isBrowser && !isCanvasKit); // https://github.com/flutter/flutter/issues/56308

packages/flutter/test/rendering/paragraph_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void main() {
121121
);
122122
layout(paragraph);
123123

124-
final double height5 = paragraph.getFullHeightForCaret(const TextPosition(offset: 5))!;
124+
final double height5 = paragraph.getFullHeightForCaret(const TextPosition(offset: 5));
125125
expect(height5, equals(10.0));
126126
});
127127

0 commit comments

Comments
 (0)