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:
parent
37bda37c38
commit
4051a38dd7
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user