Skip to content

[CP] Fix Tooltip crash when selected in a SelectableRegion #131005

@LongCatIsLooong

Description

@LongCatIsLooong

Issue Link

#129969

Commit Hash

2da353a

Target

beta

PR Link

#130181

Changelog Description

Application may crash when dragging mouse over Tooltip while selecting text in SelectionArea

Impacted Users

Devs who uses Tooltip in a SelectionArea

Impact Description

Application may crash when dragging mouse over Tooltip while selecting text in SelectionArea

Workaround

Not always possible

Risk

medium

Test Coverage

yes

Validation Steps

Follow the repro steps provided in #129969,
or run the following test:

  testWidgets('Tooltip is not selectable', (WidgetTester tester) async {
    const String tooltipText = 'AAAAAAAAAAAAAAAAAAAAAAA';
    String? selectedText;
    await tester.pumpWidget(
      MaterialApp(
        home: SelectionArea(
          onSelectionChanged: (SelectedContent? content) { selectedText = content?.plainText; },
          child: const Center(
            child: Column(
              children: <Widget>[
                Text('Select Me'),
                Tooltip(
                  message: tooltipText,
                  waitDuration: Duration(seconds: 1),
                  triggerMode: TooltipTriggerMode.longPress,
                  child: SizedBox.square(dimension: 50),
                ),
              ],
            ),
          ),
        ),
      ),
    );

    final TooltipState tooltipState = tester.state(find.byType(Tooltip));

    final Rect textRect = tester.getRect(find.text('Select Me'));
    final TestGesture gesture = await tester.startGesture(Alignment.centerLeft.alongSize(textRect.size) + textRect.topLeft);
    // Drag from centerLeft to centerRight to select the text.
    await tester.pump(const Duration(seconds: 1));
    await gesture.moveTo(Alignment.centerRight.alongSize(textRect.size) + textRect.topLeft);
    await tester.pump();

    tooltipState.ensureTooltipVisible();
    await tester.pump();
    // Make sure the tooltip becomes visible.
    expect(find.text(tooltipText), findsOneWidget);
    assert(selectedText != null);

    final Rect tooltipTextRect = tester.getRect(find.text(tooltipText));
    // Now drag from centerLeft to centerRight to select the tooltip text.
    await gesture.moveTo(Alignment.centerLeft.alongSize(tooltipTextRect.size) + tooltipTextRect.topLeft);
    await tester.pump();
    await gesture.moveTo(Alignment.centerRight.alongSize(tooltipTextRect.size) + tooltipTextRect.topLeft);
    await tester.pump();

    expect(selectedText, isNot(contains('A')));
  });

Metadata

Metadata

Assignees

Labels

cp: approvedApproved cherry-pick requestcp: merge-to-betaCherry-picks that should be merged to betacp: reviewCherry-picks in the review queue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions