diff --git a/lib/src/act/act.dart b/lib/src/act/act.dart index 77489ca3..eba6fbc1 100644 --- a/lib/src/act/act.dart +++ b/lib/src/act/act.dart @@ -260,6 +260,8 @@ class Act { final WidgetSelector scrollable = spot().withChild(dragStart).last(); + final scrollableElement = scrollable.snapshotElement(); + // Every scrollable contains a Listener handling the touch events. // We only care about the size and location of the RenderObject. final scrollableSizedRenderBox = @@ -416,13 +418,19 @@ class Act { dragCount++; } + // Take scrollable where element is scrollable element + // TODO Handle case when this is null + final scrollableWidget = spot() + .snapshot() + .discovered + .firstOrNullWhere((e) => e.element == scrollableElement) + ?.element + .widget; + // found the widget in the tree, now do a final drag to make sure it is // within the scrollable's viewport entirely - final spotScrollableBoundsAfterDrag = spot() - .withChild(dragTarget) - .last() - .spot() - .first(); + final spotScrollableBoundsAfterDrag = spotWidget(scrollableWidget!); + final scrollableSizedRenderBoxAfterDrag = spotScrollableBoundsAfterDrag.snapshotRenderBox(); final viewportGlobalPosition = diff --git a/test/act/act_drag_test.dart b/test/act/act_drag_test.dart index ae698334..766db41d 100644 --- a/test/act/act_drag_test.dart +++ b/test/act/act_drag_test.dart @@ -1,4 +1,5 @@ -import 'package:flutter/widgets.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:spot/spot.dart'; @@ -98,6 +99,44 @@ void dragTests() { secondItem.doesNotExist(); }, ); + + testWidgets( + 'Finds and taps widget in nested Column', + (tester) async { + timeline.mode = TimelineMode.always; + await tester.pumpWidget( + const MaterialApp( + localizationsDelegates: [ + DefaultMaterialLocalizations.delegate, + DefaultCupertinoLocalizations.delegate, + DefaultWidgetsLocalizations.delegate, + ], + home: DragUntilVisibleInDialogWidget(), + ), + ); + + final dialogButton = spotText('Open Dialog')..existsOnce(); + await act.tap(dialogButton); + + await tester.pump(const Duration(milliseconds: 500)); + await tester.pump(const Duration(milliseconds: 500)); + await tester.pump(const Duration(milliseconds: 500)); + await tester.pumpAndSettle(); + + final firstItem = + spotText('ParentIndex: 0, Item at index: 3', exact: true); + final secondItem = + spotText('ParentIndex: 2, Item at index: 4', exact: true); + await act.dragUntilVisible( + dragStart: firstItem, + dragTarget: secondItem, + ); + await tester.pump(const Duration(milliseconds: 500)); + await tester.pump(const Duration(milliseconds: 500)); + await tester.pumpAndSettle(); + await act.tap(secondItem); + }, + ); }); group('Horizontal Drag', () {