Unverified Commit 25c5bf06 authored by yim's avatar yim Committed by GitHub

fix SliverReorderableLists item wrong offset (#136828)

This PR fixes the issue of items being created at the wrong position during dragging.

Fixes #135819
parent 4afdfca2
......@@ -730,6 +730,9 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
}
void _registerItem(_ReorderableItemState item) {
if (_dragInfo != null && _items[item.index] != item) {
item.updateForGap(_dragInfo!.index, _dragInfo!.itemExtent, false, _reverse);
}
_items[item.index] = item;
if (item.index == _dragInfo?.index) {
item.dragging = true;
......
......@@ -1356,6 +1356,55 @@ void main() {
expect(tester.takeException(), null);
});
testWidgetsWithLeakTracking(
'When creating a new item, be in the correct position',
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: LayoutBuilder(
builder: (_, BoxConstraints view) {
// The third one just appears on the screen
final double itemSize = view.maxWidth / 2 - 20;
return Scaffold(
body: CustomScrollView(
scrollDirection: Axis.horizontal,
cacheExtent: 0, // The fourth one will not be created in the initial state.
slivers: <Widget>[
SliverReorderableList(
itemBuilder: (BuildContext context, int index) {
return ReorderableDragStartListener(
key: ValueKey<int>(index),
index: index,
child: Builder(
builder: (BuildContext context) {
return SizedBox(
width: itemSize,
child: Text('$index'),
);
},
),
);
},
itemCount: 4,
onReorder: (int fromIndex, int toIndex) {},
),
],
),
);
},
),
),
);
final TestGesture drag = await tester.startGesture(tester.getCenter(find.text('0')));
await tester.pump(kLongPressTimeout);
await drag.moveBy(const Offset(20, 0));
await tester.pump();
expect(find.text('3').hitTestable(at: Alignment.topLeft), findsNothing);
await drag.up();
await tester.pumpAndSettle();
},
);
}
class TestList extends StatelessWidget {
......
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