Skip to content

Commit

Permalink
Use pattern matching to avoid strange type annotations (flutter#131964)
Browse files Browse the repository at this point in the history
  • Loading branch information
LongCatIsLooong committed Aug 9, 2023
1 parent d7877d1 commit aac0189
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
10 changes: 4 additions & 6 deletions packages/flutter/lib/src/rendering/editable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1918,15 +1918,13 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
bool hitTestChildren(BoxHitTestResult result, { required Offset position }) {
final Offset effectivePosition = position - _paintOffset;
final InlineSpan? textSpan = _textPainter.text;
if (textSpan != null) {
final TextPosition textPosition = _textPainter.getPositionForOffset(effectivePosition);
final Object? span = textSpan.getSpanForPosition(textPosition);
if (span is HitTestTarget) {
switch (textSpan?.getSpanForPosition(_textPainter.getPositionForOffset(effectivePosition))) {
case final HitTestTarget span:
result.add(HitTestEntry(span));
return true;
}
case _:
return hitTestInlineChildren(result, effectivePosition);
}
return hitTestInlineChildren(result, effectivePosition);
}

late TapGestureRecognizer _tap;
Expand Down
11 changes: 6 additions & 5 deletions packages/flutter/lib/src/rendering/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,13 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin<RenderBo
@override
bool hitTestChildren(BoxHitTestResult result, { required Offset position }) {
final TextPosition textPosition = _textPainter.getPositionForOffset(position);
final Object? span = _textPainter.text!.getSpanForPosition(textPosition);
if (span is HitTestTarget) {
result.add(HitTestEntry(span));
return true;
switch (_textPainter.text!.getSpanForPosition(textPosition)) {
case final HitTestTarget span:
result.add(HitTestEntry(span));
return true;
case _:
return hitTestInlineChildren(result, position);
}
return hitTestInlineChildren(result, position);
}

bool _needsClipping = false;
Expand Down

0 comments on commit aac0189

Please sign in to comment.