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.
This commit is contained in:
Michael Goderbauer 2024-03-21 16:38:16 -07:00 committed by GitHub
parent 3b390c5284
commit 11c034f037
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 6 additions and 6 deletions

View file

@ -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;
}

View file

@ -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(

View file

@ -649,7 +649,7 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin<RenderBo
}
Offset _getOffsetForPosition(TextPosition position) {
return getOffsetForCaret(position, Rect.zero) + Offset(0, getFullHeightForCaret(position) ?? 0.0);
return getOffsetForCaret(position, Rect.zero) + Offset(0, getFullHeightForCaret(position));
}
@override
@ -952,7 +952,7 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin<RenderBo
/// {@macro flutter.painting.textPainter.getFullHeightForCaret}
///
/// Valid only after [layout].
double? getFullHeightForCaret(TextPosition position) {
double getFullHeightForCaret(TextPosition position) {
assert(!debugNeedsLayout);
_layoutTextWithConstraints(constraints);
return _textPainter.getFullHeightForCaret(position, Rect.zero);

View file

@ -380,7 +380,7 @@ void main() {
final double caretHeight = painter.getFullHeightForCaret(
const ui.TextPosition(offset: 0),
ui.Rect.zero,
)!;
);
expect(caretHeight, 50.0);
painter.dispose();
}, skip: isBrowser && !isCanvasKit); // https://github.com/flutter/flutter/issues/56308

View file

@ -121,7 +121,7 @@ void main() {
);
layout(paragraph);
final double height5 = paragraph.getFullHeightForCaret(const TextPosition(offset: 5))!;
final double height5 = paragraph.getFullHeightForCaret(const TextPosition(offset: 5));
expect(height5, equals(10.0));
});