Click-and-dragging in widget selection mode updates the inspected widget in DevTools (#159352)

Fixes https://github.com/flutter/devtools/issues/8539
This commit is contained in:
Elliott Brooks 2024-11-25 15:48:20 -08:00 committed by GitHub
parent 37bda37c38
commit 4051a38dd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 58 additions and 0 deletions

View File

@ -2958,6 +2958,9 @@ class _WidgetInspectorState extends State<WidgetInspector>
final Rect bounds = (Offset.zero & (view.physicalSize / view.devicePixelRatio)).deflate(_kOffScreenMargin);
if (!bounds.contains(_lastPointerLocation!)) {
selection.clear();
} else {
// Otherwise notify DevTools of the current selection.
WidgetInspectorService.instance._sendInspectEvent(selection.current);
}
}

View File

@ -414,6 +414,30 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
);
}
Future<void> panAndVerifyWidgetSelection({
required Finder startAt,
required Finder endAt,
required bool isSelected,
required GlobalKey widgetKey,
}) async {
// Pan to the widget.
final ui.Offset start = tester.getCenter(startAt);
final ui.Offset end = tester.getCenter(endAt);
await tester.dragFrom(
tester.getCenter(startAt),
Offset(end.dx - start.dx, end.dy - start.dy),
);
await tester.pump();
// Verify the pan end was intercepted by the Widget Inspector.
final RenderObject renderObject =
find.byKey(widgetKey).evaluate().first.renderObject!;
expect(
WidgetInspectorService.instance.selection.candidates,
contains(renderObject),
);
}
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
@ -475,6 +499,37 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
);
expect(log, equals(<String>[]));
// Now pan to the top button and verify it's selected in the Inspector.
await panAndVerifyWidgetSelection(
startAt: find.text('BOTTOM'),
endAt: find.text('TOP'),
isSelected: true,
widgetKey: topButtonKey,
);
expect(
paragraphText(
WidgetInspectorService.instance.selection.current! as RenderParagraph,
),
equals('TOP'),
);
expect(log, equals(<String>[]));
// Now pan to the bottom button and verify it's selected in the Inspector.
await panAndVerifyWidgetSelection(
startAt: find.text('TOP'),
endAt: find.text('BOTTOM'),
isSelected: true,
widgetKey: bottomButtonKey,
);
expect(
paragraphText(
WidgetInspectorService.instance.selection.current! as RenderParagraph,
),
equals('BOTTOM'),
);
expect(log, equals(<String>[]));
// Now exit selection mode by tapping the Exit Selection Mode button.
await tester.tap(find.byKey(exitWidgetSelectionButtonKey));
await tester.pump();