fix SliverReorderableLists item wrong offset (#136828)
This PR fixes the issue of items being created at the wrong position during dragging. Fixes #135819
This commit is contained in:
parent
4afdfca264
commit
25c5bf0640
@ -730,6 +730,9 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _registerItem(_ReorderableItemState item) {
|
void _registerItem(_ReorderableItemState item) {
|
||||||
|
if (_dragInfo != null && _items[item.index] != item) {
|
||||||
|
item.updateForGap(_dragInfo!.index, _dragInfo!.itemExtent, false, _reverse);
|
||||||
|
}
|
||||||
_items[item.index] = item;
|
_items[item.index] = item;
|
||||||
if (item.index == _dragInfo?.index) {
|
if (item.index == _dragInfo?.index) {
|
||||||
item.dragging = true;
|
item.dragging = true;
|
||||||
|
@ -1356,6 +1356,55 @@ void main() {
|
|||||||
|
|
||||||
expect(tester.takeException(), null);
|
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 {
|
class TestList extends StatelessWidget {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user