Unverified Commit cee6d46b authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Do not crash if RichText has recognizers without handlers (#69793)

parent cb5263e1
......@@ -935,13 +935,19 @@ class RenderParagraph extends RenderBox
final GestureRecognizer? recognizer = info.recognizer;
if (recognizer != null) {
if (recognizer is TapGestureRecognizer) {
configuration.onTap = recognizer.onTap;
configuration.isLink = true;
if (recognizer.onTap != null) {
configuration.onTap = recognizer.onTap;
configuration.isLink = true;
}
} else if (recognizer is DoubleTapGestureRecognizer) {
configuration.onTap = recognizer.onDoubleTap;
configuration.isLink = true;
if (recognizer.onDoubleTap != null) {
configuration.onTap = recognizer.onDoubleTap;
configuration.isLink = true;
}
} else if (recognizer is LongPressGestureRecognizer) {
configuration.onLongPress = recognizer.onLongPress;
if (recognizer.onLongPress != null) {
configuration.onLongPress = recognizer.onLongPress;
}
} else {
assert(false, '${recognizer.runtimeType} is not supported.');
}
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('RichText with recognizers without handlers does not throw', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: RichText(
text: TextSpan(text: 'root', children: <InlineSpan>[
TextSpan(text: 'one', recognizer: TapGestureRecognizer()),
TextSpan(text: 'two', recognizer: LongPressGestureRecognizer()),
TextSpan(text: 'three', recognizer: DoubleTapGestureRecognizer()),
]),
),
),
);
expect(tester.getSemantics(find.byType(RichText)), matchesSemantics(
children: <Matcher>[
matchesSemantics(
label: 'root',
hasTapAction: false,
hasLongPressAction: false,
),
matchesSemantics(
label: 'one',
hasTapAction: false,
hasLongPressAction: false,
),
matchesSemantics(
label: 'two',
hasTapAction: false,
hasLongPressAction: false,
),
matchesSemantics(
label: 'three',
hasTapAction: false,
hasLongPressAction: false,
),
],
));
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment