Skip to content

Commit edd4b41

Browse files
committed
Enhance drag functionality to directly use Scrollable as dragStart in Act class
1 parent 12f9c60 commit edd4b41

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

lib/src/act/act.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,11 @@ class Act {
266266

267267
// Take the closest Scrollable above the dragStart widget. This is the
268268
// widget which makes a widget scrollable. It must always exist.
269-
final WidgetSelector<Scrollable> scrollable =
270-
spot<Scrollable>().withChild(dragStart).last();
269+
// If dragStart is already a Scrollable, use it directly instead of searching for a parent.
270+
final WidgetSelector<Scrollable> scrollable = switch (dragStart) {
271+
final WidgetSelector<Scrollable> s => s,
272+
_ => spot<Scrollable>().withChild(dragStart).last(),
273+
};
271274

272275
// Save the 'Element' of the currently targeted Scrollable.
273276
// This ensures that—even if multiple scrollables exist or the

test/act/act_drag_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,31 @@ void dragTests() {
119119
await act.tap(secondItem);
120120
},
121121
);
122+
123+
testWidgets(
124+
'Finds widget in vertical ListView after dragging when dragStart is a Scrollable',
125+
(tester) async {
126+
await tester.pumpWidget(
127+
const DragUntilVisibleSingleDirectionTestWidget(
128+
axis: Axis.vertical,
129+
ignorePointerAtIndices: [0, 1, 2, 3, 4, 5, 6, 7, 8],
130+
),
131+
);
132+
133+
final firstItem = spot<DragUntilVisibleSingleDirectionTestWidget>()
134+
.spot<Scrollable>()
135+
.last()
136+
..existsOnce();
137+
final secondItem = spotText('Item at index: 27', exact: true)
138+
..doesNotExist();
139+
await act.dragUntilVisible(
140+
dragStart: firstItem,
141+
dragTarget: secondItem,
142+
maxIteration: 30,
143+
);
144+
secondItem.existsOnce();
145+
},
146+
);
122147
});
123148

124149
group('Horizontal Drag', () {

0 commit comments

Comments
 (0)