Skip to content

Commit d29ccad

Browse files
authored
fix SliverReorderableList not work on Android platform bug (#103406)
1 parent 04318d8 commit d29ccad

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,11 +1270,13 @@ class ReorderableDragStartListener extends StatelessWidget {
12701270
}
12711271

12721272
void _startDragging(BuildContext context, PointerDownEvent event) {
1273+
final DeviceGestureSettings? gestureSettings = MediaQuery.maybeOf(context)?.gestureSettings;
12731274
final SliverReorderableListState? list = SliverReorderableList.maybeOf(context);
12741275
list?.startItemDragReorder(
12751276
index: index,
12761277
event: event,
1277-
recognizer: createRecognizer(),
1278+
recognizer: createRecognizer()
1279+
..gestureSettings = gestureSettings,
12781280
);
12791281
}
12801282
}

packages/flutter/test/widgets/reorderable_list_test.dart

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,63 @@ import 'package:flutter/material.dart';
77
import 'package:flutter_test/flutter_test.dart';
88

99
void main() {
10+
testWidgets('SliverReorderableList works well when having gestureSettings', (WidgetTester tester) async {
11+
// Regression test for https://github.com/flutter/flutter/issues/103404
12+
const int itemCount = 5;
13+
int onReorderCallCount = 0;
14+
final List<int> items = List<int>.generate(itemCount, (int index) => index);
15+
16+
void handleReorder(int fromIndex, int toIndex) {
17+
onReorderCallCount += 1;
18+
if (toIndex > fromIndex) {
19+
toIndex -= 1;
20+
}
21+
items.insert(toIndex, items.removeAt(fromIndex));
22+
}
23+
// The list has five elements of height 100
24+
await tester.pumpWidget(
25+
MaterialApp(
26+
home: MediaQuery(
27+
data: const MediaQueryData(gestureSettings: DeviceGestureSettings(touchSlop: 8.0)),
28+
child: CustomScrollView(
29+
slivers: <Widget>[
30+
SliverReorderableList(
31+
itemCount: itemCount,
32+
itemBuilder: (BuildContext context, int index) {
33+
return SizedBox(
34+
key: ValueKey<int>(items[index]),
35+
height: 100,
36+
child: ReorderableDragStartListener(
37+
index: index,
38+
child: Text('item ${items[index]}'),
39+
),
40+
);
41+
},
42+
onReorder: handleReorder,
43+
)
44+
],
45+
),
46+
),
47+
),
48+
);
49+
50+
// Start gesture on first item
51+
final TestGesture drag = await tester.startGesture(tester.getCenter(find.text('item 0')));
52+
await tester.pump(kPressTimeout);
53+
54+
// Drag a little bit to make `ImmediateMultiDragGestureRecognizer` compete with `VerticalDragGestureRecognizer`
55+
await drag.moveBy(const Offset(0, 10));
56+
await tester.pump();
57+
// Drag enough to move down the first item
58+
await drag.moveBy(const Offset(0, 40));
59+
await tester.pump();
60+
await drag.up();
61+
await tester.pumpAndSettle();
62+
63+
expect(onReorderCallCount, 1);
64+
expect(items, orderedEquals(<int>[1, 0, 2, 3, 4]));
65+
});
66+
1067
// Regression test for https://github.com/flutter/flutter/issues/100451
1168
testWidgets('SliverReorderableList.builder respects findChildIndexCallback', (WidgetTester tester) async {
1269
bool finderCalled = false;

0 commit comments

Comments
 (0)