diff --git a/packages/flutter/lib/src/material/reorderable_list.dart b/packages/flutter/lib/src/material/reorderable_list.dart index 29bf6d91c6..13f877c86b 100644 --- a/packages/flutter/lib/src/material/reorderable_list.dart +++ b/packages/flutter/lib/src/material/reorderable_list.dart @@ -369,25 +369,48 @@ class _ReorderableListViewState extends State { case TargetPlatform.linux: case TargetPlatform.windows: case TargetPlatform.macOS: - return Stack( - key: itemGlobalKey, - children: [ - itemWithSemantics, - Positioned.directional( - textDirection: Directionality.of(context), - top: 0, - bottom: 0, - end: 8, - child: Align( - alignment: AlignmentDirectional.centerEnd, - child: ReorderableDragStartListener( - index: index, - child: const Icon(Icons.drag_handle), + switch (widget.scrollDirection) { + case Axis.horizontal: + return Stack( + key: itemGlobalKey, + children: [ + itemWithSemantics, + Positioned.directional( + textDirection: Directionality.of(context), + start: 0, + end: 0, + bottom: 8, + child: Align( + alignment: AlignmentDirectional.bottomCenter, + child: ReorderableDragStartListener( + index: index, + child: const Icon(Icons.drag_handle), + ), + ), ), - ), - ), - ], - ); + ], + ); + case Axis.vertical: + return Stack( + key: itemGlobalKey, + children: [ + itemWithSemantics, + Positioned.directional( + textDirection: Directionality.of(context), + top: 0, + bottom: 0, + end: 8, + child: Align( + alignment: AlignmentDirectional.centerEnd, + child: ReorderableDragStartListener( + index: index, + child: const Icon(Icons.drag_handle), + ), + ), + ), + ], + ); + } case TargetPlatform.iOS: case TargetPlatform.android: diff --git a/packages/flutter/test/material/reorderable_list_test.dart b/packages/flutter/test/material/reorderable_list_test.dart index e1d57cec0b..5224f691b2 100644 --- a/packages/flutter/test/material/reorderable_list_test.dart +++ b/packages/flutter/test/material/reorderable_list_test.dart @@ -30,8 +30,14 @@ void main() { ); } - Widget build({ Widget? header, Axis scrollDirection = Axis.vertical, TextDirection textDirection = TextDirection.ltr }) { + Widget build({ + Widget? header, + Axis scrollDirection = Axis.vertical, + TextDirection textDirection = TextDirection.ltr, + TargetPlatform? platform, + }) { return MaterialApp( + theme: ThemeData(platform: platform), home: Directionality( textDirection: textDirection, child: SizedBox( @@ -1309,6 +1315,28 @@ void main() { expect(getTestItemPosition(), startPosition); }); // TODO(djshuckerow): figure out how to write a test for scrolling the list. + + testWidgets('Vertical list renders drag handle in correct position', (WidgetTester tester) async { + await tester.pumpWidget(build(platform: TargetPlatform.macOS)); + final Finder listView = find.byType(ReorderableListView); + final Finder item1 = find.byKey(const Key('Item 1')); + final Finder dragHandle = find.byIcon(Icons.drag_handle).first; + + // Should be centered vertically within the item and 8 pixels from the right edge of the list. + expect(tester.getCenter(dragHandle).dy, tester.getCenter(item1).dy); + expect(tester.getTopRight(dragHandle).dx, tester.getSize(listView).width - 8); + }); + + testWidgets('Horizontal list renders drag handle in correct position', (WidgetTester tester) async { + await tester.pumpWidget(build(scrollDirection: Axis.horizontal, platform: TargetPlatform.macOS)); + final Finder listView = find.byType(ReorderableListView); + final Finder item1 = find.byKey(const Key('Item 1')); + final Finder dragHandle = find.byIcon(Icons.drag_handle).first; + + // Should be centered horizontally within the item and 8 pixels from the bottom of the list. + expect(tester.getCenter(dragHandle).dx, tester.getCenter(item1).dx); + expect(tester.getBottomRight(dragHandle).dy, tester.getSize(listView).height - 8); + }); }); testWidgets('ReorderableListView, can deal with the dragged item getting unmounted and rebuilt during drag', (WidgetTester tester) async {