Unverified Commit d5bee36d authored by hangyu's avatar hangyu Committed by GitHub

Fix an reorderable list animation issue:"Reversed ReorderableListView drop...

Fix an reorderable list animation issue:"Reversed ReorderableListView drop animation moves item one row higher than it should #110949" (#111027)
parent 6206fbff
......@@ -758,9 +758,11 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
void _dragEnd(_DragInfo item) {
setState(() {
if (_insertIndex! < widget.itemCount - 1) {
// Find the location of the item we want to insert before
if (_insertIndex == item.index) {
_finalDropPosition = _itemOffsetAt(_insertIndex! + (_reverse ? 1 : 0));
} else if (_insertIndex! < widget.itemCount - 1) {
// Find the location of the item we want to insert before
_finalDropPosition = _itemOffsetAt(_insertIndex!);
} else {
// Inserting into the last spot on the list. If it's the only spot, put
// it back where it was. Otherwise, grab the second to last and move
......
......@@ -521,6 +521,57 @@ void main() {
expect(tester.takeException(), isNull);
});
testWidgets('SliverReorderableList - properly animates the drop in a reversed list', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/110949
final List<int> items = List<int>.generate(8, (int index) => index);
Future<void> pressDragRelease(Offset start, Offset delta) async {
final TestGesture drag = await tester.startGesture(start);
await tester.pump(kPressTimeout);
await drag.moveBy(delta);
await tester.pumpAndSettle();
await drag.up();
await tester.pump();
}
// The TestList is 800x600 SliverReorderableList with 8 items 800x100 each.
// Each item has a text widget with 'item $index' that can be moved by a
// press and drag gesture. For this test we are reversing the order so
// the first item is at the bottom.
await tester.pumpWidget(TestList(items: items, reverse: true));
expect(tester.getTopLeft(find.text('item 0')), const Offset(0, 500));
expect(tester.getTopLeft(find.text('item 2')), const Offset(0, 300));
// Drag item 0 up and insert it between item 1 and item 2. It should
// smoothly animate.
await pressDragRelease(tester.getCenter(find.text('item 0')), const Offset(0, -50));
expect(tester.getTopLeft(find.text('item 0')), const Offset(0, 450));
expect(tester.getTopLeft(find.text('item 1')), const Offset(0, 500));
expect(tester.getTopLeft(find.text('item 2')), const Offset(0, 300));
// After the first several frames we should be moving closer to the final position,
// not further away as was the case with the original bug.
await tester.pump(const Duration(milliseconds: 10));
expect(tester.getTopLeft(find.text('item 0')).dy, lessThan(450));
expect(tester.getTopLeft(find.text('item 0')).dy, greaterThan(400));
// Sample the middle (don't use exact values as it depends on the internal
// curve being used).
await tester.pump(const Duration(milliseconds: 125));
expect(tester.getTopLeft(find.text('item 0')).dy, lessThan(450));
expect(tester.getTopLeft(find.text('item 0')).dy, greaterThan(400));
// Sample the end of the animation.
await tester.pump(const Duration(milliseconds: 100));
expect(tester.getTopLeft(find.text('item 0')).dy, lessThan(450));
expect(tester.getTopLeft(find.text('item 0')).dy, greaterThan(400));
// Wait for it to finish, it should be back to the original position
await tester.pumpAndSettle();
expect(tester.getTopLeft(find.text('item 0')), const Offset(0, 400));
});
testWidgets('SliverReorderableList - properly animates the drop at starting position in a reversed list', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/84625
final List<int> items = List<int>.generate(8, (int index) => index);
......
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