Use pattern matching to avoid strange type annotations (#131964)

Addresses https://github.com/flutter/flutter/pull/131640#discussion_r1284861384
This commit is contained in:
LongCatIsLooong 2023-08-08 21:43:57 -07:00 committed by GitHub
parent d7877d1fe0
commit aac018974f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 11 deletions

View File

@ -1918,15 +1918,13 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { bool hitTestChildren(BoxHitTestResult result, { required Offset position }) {
final Offset effectivePosition = position - _paintOffset; final Offset effectivePosition = position - _paintOffset;
final InlineSpan? textSpan = _textPainter.text; final InlineSpan? textSpan = _textPainter.text;
if (textSpan != null) { switch (textSpan?.getSpanForPosition(_textPainter.getPositionForOffset(effectivePosition))) {
final TextPosition textPosition = _textPainter.getPositionForOffset(effectivePosition); case final HitTestTarget span:
final Object? span = textSpan.getSpanForPosition(textPosition);
if (span is HitTestTarget) {
result.add(HitTestEntry(span)); result.add(HitTestEntry(span));
return true; return true;
} case _:
return hitTestInlineChildren(result, effectivePosition);
} }
return hitTestInlineChildren(result, effectivePosition);
} }
late TapGestureRecognizer _tap; late TapGestureRecognizer _tap;

View File

@ -725,12 +725,13 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin<RenderBo
@override @override
bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { bool hitTestChildren(BoxHitTestResult result, { required Offset position }) {
final TextPosition textPosition = _textPainter.getPositionForOffset(position); final TextPosition textPosition = _textPainter.getPositionForOffset(position);
final Object? span = _textPainter.text!.getSpanForPosition(textPosition); switch (_textPainter.text!.getSpanForPosition(textPosition)) {
if (span is HitTestTarget) { case final HitTestTarget span:
result.add(HitTestEntry(span)); result.add(HitTestEntry(span));
return true; return true;
case _:
return hitTestInlineChildren(result, position);
} }
return hitTestInlineChildren(result, position);
} }
bool _needsClipping = false; bool _needsClipping = false;