mirror of
https://github.com/flutter/flutter
synced 2024-08-25 02:46:31 +00:00
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:
parent
3b390c5284
commit
11c034f037
|
@ -1352,7 +1352,7 @@ class TextPainter {
|
||||||
/// {@endtemplate}
|
/// {@endtemplate}
|
||||||
///
|
///
|
||||||
/// Valid only after [layout] has been called.
|
/// 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;
|
final TextBox textBox = _getOrCreateLayoutTemplate().getBoxesForRange(0, 1, boxHeightStyle: ui.BoxHeightStyle.strut).single;
|
||||||
return textBox.toRect().height;
|
return textBox.toRect().height;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1798,7 +1798,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
|
||||||
switch (defaultTargetPlatform) {
|
switch (defaultTargetPlatform) {
|
||||||
case TargetPlatform.iOS:
|
case TargetPlatform.iOS:
|
||||||
case TargetPlatform.macOS:
|
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;
|
final double heightDiff = fullHeight - caretRect.height;
|
||||||
// Center the caret vertically along the text.
|
// Center the caret vertically along the text.
|
||||||
caretRect = Rect.fromLTWH(
|
caretRect = Rect.fromLTWH(
|
||||||
|
|
|
@ -649,7 +649,7 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin<RenderBo
|
||||||
}
|
}
|
||||||
|
|
||||||
Offset _getOffsetForPosition(TextPosition position) {
|
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
|
@override
|
||||||
|
@ -952,7 +952,7 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin<RenderBo
|
||||||
/// {@macro flutter.painting.textPainter.getFullHeightForCaret}
|
/// {@macro flutter.painting.textPainter.getFullHeightForCaret}
|
||||||
///
|
///
|
||||||
/// Valid only after [layout].
|
/// Valid only after [layout].
|
||||||
double? getFullHeightForCaret(TextPosition position) {
|
double getFullHeightForCaret(TextPosition position) {
|
||||||
assert(!debugNeedsLayout);
|
assert(!debugNeedsLayout);
|
||||||
_layoutTextWithConstraints(constraints);
|
_layoutTextWithConstraints(constraints);
|
||||||
return _textPainter.getFullHeightForCaret(position, Rect.zero);
|
return _textPainter.getFullHeightForCaret(position, Rect.zero);
|
||||||
|
|
|
@ -380,7 +380,7 @@ void main() {
|
||||||
final double caretHeight = painter.getFullHeightForCaret(
|
final double caretHeight = painter.getFullHeightForCaret(
|
||||||
const ui.TextPosition(offset: 0),
|
const ui.TextPosition(offset: 0),
|
||||||
ui.Rect.zero,
|
ui.Rect.zero,
|
||||||
)!;
|
);
|
||||||
expect(caretHeight, 50.0);
|
expect(caretHeight, 50.0);
|
||||||
painter.dispose();
|
painter.dispose();
|
||||||
}, skip: isBrowser && !isCanvasKit); // https://github.com/flutter/flutter/issues/56308
|
}, skip: isBrowser && !isCanvasKit); // https://github.com/flutter/flutter/issues/56308
|
||||||
|
|
|
@ -121,7 +121,7 @@ void main() {
|
||||||
);
|
);
|
||||||
layout(paragraph);
|
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));
|
expect(height5, equals(10.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue