Skip to content

Commit 4051a38

Browse files
authored
Click-and-dragging in widget selection mode updates the inspected widget in DevTools (flutter#159352)
Fixes flutter/devtools#8539
1 parent 37bda37 commit 4051a38

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

packages/flutter/lib/src/widgets/widget_inspector.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,6 +2958,9 @@ class _WidgetInspectorState extends State<WidgetInspector>
29582958
final Rect bounds = (Offset.zero & (view.physicalSize / view.devicePixelRatio)).deflate(_kOffScreenMargin);
29592959
if (!bounds.contains(_lastPointerLocation!)) {
29602960
selection.clear();
2961+
} else {
2962+
// Otherwise notify DevTools of the current selection.
2963+
WidgetInspectorService.instance._sendInspectEvent(selection.current);
29612964
}
29622965
}
29632966

packages/flutter/test/widgets/widget_inspector_test.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,30 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
414414
);
415415
}
416416

417+
Future<void> panAndVerifyWidgetSelection({
418+
required Finder startAt,
419+
required Finder endAt,
420+
required bool isSelected,
421+
required GlobalKey widgetKey,
422+
}) async {
423+
// Pan to the widget.
424+
final ui.Offset start = tester.getCenter(startAt);
425+
final ui.Offset end = tester.getCenter(endAt);
426+
await tester.dragFrom(
427+
tester.getCenter(startAt),
428+
Offset(end.dx - start.dx, end.dy - start.dy),
429+
);
430+
await tester.pump();
431+
432+
// Verify the pan end was intercepted by the Widget Inspector.
433+
final RenderObject renderObject =
434+
find.byKey(widgetKey).evaluate().first.renderObject!;
435+
expect(
436+
WidgetInspectorService.instance.selection.candidates,
437+
contains(renderObject),
438+
);
439+
}
440+
417441
await tester.pumpWidget(
418442
Directionality(
419443
textDirection: TextDirection.ltr,
@@ -475,6 +499,37 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
475499
);
476500
expect(log, equals(<String>[]));
477501

502+
503+
// Now pan to the top button and verify it's selected in the Inspector.
504+
await panAndVerifyWidgetSelection(
505+
startAt: find.text('BOTTOM'),
506+
endAt: find.text('TOP'),
507+
isSelected: true,
508+
widgetKey: topButtonKey,
509+
);
510+
expect(
511+
paragraphText(
512+
WidgetInspectorService.instance.selection.current! as RenderParagraph,
513+
),
514+
equals('TOP'),
515+
);
516+
expect(log, equals(<String>[]));
517+
518+
// Now pan to the bottom button and verify it's selected in the Inspector.
519+
await panAndVerifyWidgetSelection(
520+
startAt: find.text('TOP'),
521+
endAt: find.text('BOTTOM'),
522+
isSelected: true,
523+
widgetKey: bottomButtonKey,
524+
);
525+
expect(
526+
paragraphText(
527+
WidgetInspectorService.instance.selection.current! as RenderParagraph,
528+
),
529+
equals('BOTTOM'),
530+
);
531+
expect(log, equals(<String>[]));
532+
478533
// Now exit selection mode by tapping the Exit Selection Mode button.
479534
await tester.tap(find.byKey(exitWidgetSelectionButtonKey));
480535
await tester.pump();

0 commit comments

Comments
 (0)