Unverified Commit e0c0321e authored by nero's avatar nero Committed by GitHub

[ReorderableListView] Fix item dropping animation (#64140)

parent 30c0fc1b
...@@ -381,8 +381,8 @@ class _ReorderableListContentState extends State<_ReorderableListContent> with T ...@@ -381,8 +381,8 @@ class _ReorderableListContentState extends State<_ReorderableListContent> with T
if (startIndex != endIndex) if (startIndex != endIndex)
widget.onReorder(startIndex, endIndex); widget.onReorder(startIndex, endIndex);
// Animates leftover space in the drop area closed. // Animates leftover space in the drop area closed.
_ghostController.reverse(from: 0.1); _ghostController.reverse(from: 0);
_entranceController.reverse(from: 0.1); _entranceController.reverse(from: 0);
_dragging = null; _dragging = null;
}); });
} }
......
...@@ -1173,6 +1173,58 @@ void main() { ...@@ -1173,6 +1173,58 @@ void main() {
)); ));
expect(tester.getCenter(find.text('A')).dy, lessThan(tester.getCenter(find.text('B')).dy)); expect(tester.getCenter(find.text('A')).dy, lessThan(tester.getCenter(find.text('B')).dy));
}); });
testWidgets('Animation test when placing an item in place', (WidgetTester tester) async {
const Key testItemKey = Key('Test item');
final Widget reorderableListView = ReorderableListView(
children: const <Widget>[
SizedBox(
key: Key('First item'),
height: itemHeight,
child: Text('First item'),
),
SizedBox(
key: testItemKey,
height: itemHeight,
child: Text('Test item'),
),
SizedBox(
key: Key('Last item'),
height: itemHeight,
child: Text('Last item'),
),
],
scrollDirection: Axis.vertical,
onReorder: (int oldIndex, int newIndex) { },
);
await tester.pumpWidget(MaterialApp(
home: SizedBox(
height: itemHeight * 10,
child: reorderableListView,
),
));
Offset getTestItemPosition() {
final RenderBox testItem = tester.renderObject<RenderBox>(find.byKey(testItemKey));
return testItem.localToGlobal(Offset.zero);
}
// Before pick it up.
final Offset startPosition = getTestItemPosition();
// Pick it up.
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byKey(testItemKey)));
await tester.pump(kLongPressTimeout + kPressTimeout);
expect(getTestItemPosition(), startPosition);
// Put it down.
await gesture.up();
await tester.pump();
expect(getTestItemPosition(), startPosition);
// After put it down.
await tester.pumpAndSettle();
expect(getTestItemPosition(), startPosition);
});
// TODO(djshuckerow): figure out how to write a test for scrolling the list. // TODO(djshuckerow): figure out how to write a test for scrolling the list.
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment