mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[ReorderableListView] remove extra margin added after picking up the item (#65080)
This commit is contained in:
parent
1415078828
commit
021c2010df
@ -206,9 +206,6 @@ class _ReorderableListContentState extends State<_ReorderableListContent> with T
|
||||
// the currently dragging widget, such as when it first builds.
|
||||
static const double _defaultDropAreaExtent = 100.0;
|
||||
|
||||
// The additional margin to place around a computed drop area.
|
||||
static const double _dropAreaMargin = 8.0;
|
||||
|
||||
// How long an animation to reorder an element in the list takes.
|
||||
static const Duration _reorderAnimationDuration = Duration(milliseconds: 200);
|
||||
|
||||
@ -264,7 +261,7 @@ class _ReorderableListContentState extends State<_ReorderableListContent> with T
|
||||
dropAreaWithoutMargin = _draggingFeedbackSize.height;
|
||||
break;
|
||||
}
|
||||
return dropAreaWithoutMargin + _dropAreaMargin;
|
||||
return dropAreaWithoutMargin;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -177,11 +177,9 @@ void main() {
|
||||
return contentElement;
|
||||
}
|
||||
|
||||
const double kNonDraggingListHeight = 292.0;
|
||||
// The list view pads the drop area by 8dp.
|
||||
const double kDraggingListHeight = 300.0;
|
||||
const double kDraggingListHeight = 292.0;
|
||||
// Drag a normal text item
|
||||
expect(getContentElement().size.height, kNonDraggingListHeight);
|
||||
expect(getContentElement().size.height, kDraggingListHeight);
|
||||
TestGesture drag = await tester.startGesture(tester.getCenter(find.text('Normal item')));
|
||||
await tester.pump(kLongPressTimeout + kPressTimeout);
|
||||
await tester.pumpAndSettle();
|
||||
@ -195,7 +193,7 @@ void main() {
|
||||
// Drop it
|
||||
await drag.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(getContentElement().size.height, kNonDraggingListHeight);
|
||||
expect(getContentElement().size.height, kDraggingListHeight);
|
||||
|
||||
// Drag a tall item
|
||||
drag = await tester.startGesture(tester.getCenter(find.text('Tall item')));
|
||||
@ -210,7 +208,48 @@ void main() {
|
||||
// Drop it
|
||||
await drag.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(getContentElement().size.height, kNonDraggingListHeight);
|
||||
expect(getContentElement().size.height, kDraggingListHeight);
|
||||
});
|
||||
|
||||
testWidgets('Vertical drop area golden', (WidgetTester tester) async {
|
||||
final Widget reorderableListView = ReorderableListView(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
key: const Key('pink'),
|
||||
width: double.infinity,
|
||||
height: itemHeight,
|
||||
color: Colors.pink,
|
||||
),
|
||||
Container(
|
||||
key: const Key('blue'),
|
||||
width: double.infinity,
|
||||
height: itemHeight,
|
||||
color: Colors.blue,
|
||||
),
|
||||
Container(
|
||||
key: const Key('green'),
|
||||
width: double.infinity,
|
||||
height: itemHeight,
|
||||
color: Colors.green,
|
||||
),
|
||||
],
|
||||
scrollDirection: Axis.vertical,
|
||||
onReorder: (int oldIndex, int newIndex) { },
|
||||
);
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: SizedBox(
|
||||
height: itemHeight * 3,
|
||||
child: reorderableListView,
|
||||
),
|
||||
));
|
||||
|
||||
await tester.startGesture(tester.getCenter(find.byKey(const Key('blue'))));
|
||||
await tester.pump(kLongPressTimeout + kPressTimeout);
|
||||
await tester.pumpAndSettle();
|
||||
await expectLater(
|
||||
find.byKey(const Key('blue')),
|
||||
matchesGoldenFile('reorderable_list_test.vertical.drop_area.png'),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Preserves children states when the list parent changes the order', (WidgetTester tester) async {
|
||||
@ -721,11 +760,9 @@ void main() {
|
||||
return contentElement;
|
||||
}
|
||||
|
||||
const double kNonDraggingListWidth = 292.0;
|
||||
// The list view pads the drop area by 8dp.
|
||||
const double kDraggingListWidth = 300.0;
|
||||
const double kDraggingListWidth = 292.0;
|
||||
// Drag a normal text item
|
||||
expect(getContentElement().size.width, kNonDraggingListWidth);
|
||||
expect(getContentElement().size.width, kDraggingListWidth);
|
||||
TestGesture drag = await tester.startGesture(tester.getCenter(find.text('Normal item')));
|
||||
await tester.pump(kLongPressTimeout + kPressTimeout);
|
||||
await tester.pumpAndSettle();
|
||||
@ -739,7 +776,7 @@ void main() {
|
||||
// Drop it
|
||||
await drag.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(getContentElement().size.width, kNonDraggingListWidth);
|
||||
expect(getContentElement().size.width, kDraggingListWidth);
|
||||
|
||||
// Drag a tall item
|
||||
drag = await tester.startGesture(tester.getCenter(find.text('Tall item')));
|
||||
@ -754,9 +791,49 @@ void main() {
|
||||
// Drop it
|
||||
await drag.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(getContentElement().size.width, kNonDraggingListWidth);
|
||||
expect(getContentElement().size.width, kDraggingListWidth);
|
||||
});
|
||||
|
||||
testWidgets('Horizontal drop area golden', (WidgetTester tester) async {
|
||||
final Widget reorderableListView = ReorderableListView(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
key: const Key('pink'),
|
||||
height: double.infinity,
|
||||
width: itemHeight,
|
||||
color: Colors.pink,
|
||||
),
|
||||
Container(
|
||||
key: const Key('blue'),
|
||||
height: double.infinity,
|
||||
width: itemHeight,
|
||||
color: Colors.blue,
|
||||
),
|
||||
Container(
|
||||
key: const Key('green'),
|
||||
height: double.infinity,
|
||||
width: itemHeight,
|
||||
color: Colors.green,
|
||||
),
|
||||
],
|
||||
scrollDirection: Axis.horizontal,
|
||||
onReorder: (int oldIndex, int newIndex) { },
|
||||
);
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: SizedBox(
|
||||
width: itemHeight * 3,
|
||||
child: reorderableListView,
|
||||
),
|
||||
));
|
||||
|
||||
await tester.startGesture(tester.getCenter(find.byKey(const Key('blue'))));
|
||||
await tester.pump(kLongPressTimeout + kPressTimeout);
|
||||
await tester.pumpAndSettle();
|
||||
await expectLater(
|
||||
find.byKey(const Key('blue')),
|
||||
matchesGoldenFile('reorderable_list_test.horizontal.drop_area.png'),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Preserves children states when the list parent changes the order', (WidgetTester tester) async {
|
||||
_StatefulState findState(Key key) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user