diff --git a/packages/flutter/lib/src/material/reorderable_list.dart b/packages/flutter/lib/src/material/reorderable_list.dart index 3c95333cc6..a91f2a47e8 100644 --- a/packages/flutter/lib/src/material/reorderable_list.dart +++ b/packages/flutter/lib/src/material/reorderable_list.dart @@ -273,6 +273,8 @@ class ReorderableListView extends StatefulWidget { final Widget? prototypeItem; /// {@macro flutter.widgets.EdgeDraggingAutoScroller.velocityScalar} + /// + /// {@macro flutter.widgets.SliverReorderableList.autoScrollerVelocityScalar.default} final double? autoScrollerVelocityScalar; @override diff --git a/packages/flutter/lib/src/widgets/reorderable_list.dart b/packages/flutter/lib/src/widgets/reorderable_list.dart index 24465c819d..cb9de37dec 100644 --- a/packages/flutter/lib/src/widgets/reorderable_list.dart +++ b/packages/flutter/lib/src/widgets/reorderable_list.dart @@ -257,6 +257,8 @@ class ReorderableList extends StatefulWidget { final Widget? prototypeItem; /// {@macro flutter.widgets.EdgeDraggingAutoScroller.velocityScalar} + /// + /// {@macro flutter.widgets.SliverReorderableList.autoScrollerVelocityScalar.default} final double? autoScrollerVelocityScalar; /// The state from the closest instance of this class that encloses the given @@ -450,13 +452,17 @@ class SliverReorderableList extends StatefulWidget { this.itemExtent, this.prototypeItem, this.proxyDecorator, - this.autoScrollerVelocityScalar, - }) : assert(itemCount >= 0), + double? autoScrollerVelocityScalar, + }) : autoScrollerVelocityScalar = autoScrollerVelocityScalar ?? _kDefaultAutoScrollVelocityScalar, + assert(itemCount >= 0), assert( itemExtent == null || prototypeItem == null, 'You can only pass itemExtent or prototypeItem, not both', ); + // An eyeballed value for a smooth scrolling experience. + static const double _kDefaultAutoScrollVelocityScalar = 50; + /// {@macro flutter.widgets.reorderable_list.itemBuilder} final IndexedWidgetBuilder itemBuilder; @@ -485,7 +491,11 @@ class SliverReorderableList extends StatefulWidget { final Widget? prototypeItem; /// {@macro flutter.widgets.EdgeDraggingAutoScroller.velocityScalar} - final double? autoScrollerVelocityScalar; + /// + /// {@template flutter.widgets.SliverReorderableList.autoScrollerVelocityScalar.default} + /// Defaults to 50 if not set or set to null. + /// {@endtemplate} + final double autoScrollerVelocityScalar; @override SliverReorderableListState createState() => SliverReorderableListState(); diff --git a/packages/flutter/lib/src/widgets/scrollable_helpers.dart b/packages/flutter/lib/src/widgets/scrollable_helpers.dart index 5dbd9e40d8..4e50c4a005 100644 --- a/packages/flutter/lib/src/widgets/scrollable_helpers.dart +++ b/packages/flutter/lib/src/widgets/scrollable_helpers.dart @@ -158,11 +158,8 @@ class EdgeDraggingAutoScroller { EdgeDraggingAutoScroller( this.scrollable, { this.onScrollViewScrolled, - double? velocityScalar, - }): velocityScalar = velocityScalar ?? _kDefaultAutoScrollVelocityScalar; - - // An eyeballed value for a smooth scrolling experience. - static const double _kDefaultAutoScrollVelocityScalar = 7; + required this.velocityScalar, + }); /// The [Scrollable] this auto scroller is scrolling. final ScrollableState scrollable; @@ -179,8 +176,6 @@ class EdgeDraggingAutoScroller { /// /// It represents how the velocity scale with the over scroll distance. The /// auto-scroll velocity = * velocityScalar. - /// - /// Defaults to 7 if not set or set to null. /// {@endtemplate} final double velocityScalar; diff --git a/packages/flutter/test/material/reorderable_list_test.dart b/packages/flutter/test/material/reorderable_list_test.dart index d159176a1a..6bcf56fe5f 100644 --- a/packages/flutter/test/material/reorderable_list_test.dart +++ b/packages/flutter/test/material/reorderable_list_test.dart @@ -474,6 +474,45 @@ void main() { expect(customController.offset, 120.0); }); + testWidgets('ReorderableList auto scrolling is fast enough', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/121603. + final ScrollController controller = ScrollController(); + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: ReorderableListView.builder( + scrollController: controller, + itemCount: 100, + itemBuilder: (BuildContext context, int index) { + return Text('data', key: ValueKey(index)); + }, + onReorder: (int oldIndex, int newIndex) {}, + ), + ), + ), + ); + + // Start gesture on first item. + final TestGesture drag = await tester.startGesture(tester.getCenter(find.byKey(const ValueKey(0)))); + await tester.pump(kLongPressTimeout + kPressTimeout); + final Offset bottomRight = tester.getBottomRight(find.byType(ReorderableListView)); + // Drag enough for move to start. + await drag.moveTo(Offset(bottomRight.dx / 2, bottomRight.dy)); + await tester.pump(); + // Use a fixed value to make sure the default velocity scalar is bigger + // than a certain amount. + const double kMinimumAllowedAutoScrollDistancePer5ms = 1.7; + + await tester.pump(const Duration(milliseconds: 5)); + expect(controller.offset, greaterThan(kMinimumAllowedAutoScrollDistancePer5ms)); + await tester.pump(const Duration(milliseconds: 5)); + expect(controller.offset, greaterThan(kMinimumAllowedAutoScrollDistancePer5ms * 2)); + await tester.pump(const Duration(milliseconds: 5)); + expect(controller.offset, greaterThan(kMinimumAllowedAutoScrollDistancePer5ms * 3)); + await tester.pump(const Duration(milliseconds: 5)); + expect(controller.offset, greaterThan(kMinimumAllowedAutoScrollDistancePer5ms * 4)); + }); + testWidgets('Still builds when no PrimaryScrollController is available', (WidgetTester tester) async { final Widget reorderableList = ReorderableListView( children: const [