Skip to content

Commit

Permalink
Merge pull request #11 from lukepighetti/lukepighetti/disable-autoscroll
Browse files Browse the repository at this point in the history
LGTM, thanks
  • Loading branch information
casvanluijtelaar committed Jun 7, 2022
2 parents 115465d + 7e456ae commit 6a2c590
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/src/reorderable_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ReorderableGrid extends StatefulWidget {
this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
this.restorationId,
this.clipBehavior = Clip.hardEdge,
this.autoScroll,
}) : assert(itemCount >= 0),
super(key: key);

Expand Down Expand Up @@ -121,6 +122,10 @@ class ReorderableGrid extends StatefulWidget {

final SliverGridDelegate gridDelegate;

/// Overrides if autoscrolling is enabled. Defaults to false if `physics` is
/// [NeverScrollableScrollPhysics]
final bool? autoScroll;

/// The state from the closest instance of this class that encloses the given
/// context.
///
Expand Down Expand Up @@ -258,6 +263,8 @@ class ReorderableGridState extends State<ReorderableGrid> {
itemCount: widget.itemCount,
onReorder: widget.onReorder,
proxyDecorator: widget.proxyDecorator,
autoScroll: widget.autoScroll ??
widget.physics is! NeverScrollableScrollPhysics,
),
),
],
Expand Down Expand Up @@ -297,6 +304,7 @@ class SliverReorderableGrid extends StatefulWidget {
required this.onReorder,
required this.gridDelegate,
this.proxyDecorator,
this.autoScroll = true,
}) : assert(itemCount >= 0),
super(key: key);

Expand All @@ -314,6 +322,10 @@ class SliverReorderableGrid extends StatefulWidget {

final SliverGridDelegate gridDelegate;

/// If auto scrolling is enabled. Should be disabled if associated scroll
/// physics are [NeverScrollableScrollPhysics]
final bool autoScroll;

@override
SliverReorderableGridState createState() => SliverReorderableGridState();

Expand Down Expand Up @@ -589,7 +601,10 @@ class SliverReorderableGridState extends State<SliverReorderableGrid>
}

Future<void> _autoScrollIfNecessary() async {
if (_autoScrolling || _dragInfo == null || _dragInfo!.scrollable == null) {
if (_autoScrolling ||
_dragInfo == null ||
_dragInfo!.scrollable == null ||
widget.autoScroll == false) {
return;
}

Expand Down
10 changes: 10 additions & 0 deletions lib/src/reorderable_grid_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ class ReorderableGridView extends StatefulWidget {
this.scrollController,
this.anchor = 0.0,
this.proxyDecorator,
this.autoScroll,
}) : assert(
children.every((Widget w) => w.key != null),
'All children of this widget must have a key.',
Expand Down Expand Up @@ -304,6 +305,7 @@ class ReorderableGridView extends StatefulWidget {
this.scrollController,
this.anchor = 0.0,
this.proxyDecorator,
this.autoScroll,
}) : assert(itemCount >= 0),
super(key: key);

Expand Down Expand Up @@ -345,6 +347,7 @@ class ReorderableGridView extends StatefulWidget {
this.scrollController,
this.anchor = 0.0,
this.proxyDecorator,
this.autoScroll,
}) : gridDelegate = SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount,
mainAxisSpacing: mainAxisSpacing,
Expand Down Expand Up @@ -397,6 +400,7 @@ class ReorderableGridView extends StatefulWidget {
this.scrollController,
this.anchor = 0.0,
this.proxyDecorator,
this.autoScroll,
}) : gridDelegate = SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: maxCrossAxisExtent,
mainAxisSpacing: mainAxisSpacing,
Expand Down Expand Up @@ -477,6 +481,10 @@ class ReorderableGridView extends StatefulWidget {
/// {@macro flutter.widgets.reorderable_list.proxyDecorator}
final ReorderItemProxyDecorator? proxyDecorator;

/// Overrides if autoscrolling is enabled. Defaults to false if `physics` is
/// [NeverScrollableScrollPhysics]
final bool? autoScroll;

@override
_ReorderableGridViewState createState() => _ReorderableGridViewState();
}
Expand Down Expand Up @@ -625,6 +633,8 @@ class _ReorderableGridViewState extends State<ReorderableGridView> {
itemCount: widget.itemCount,
onReorder: widget.onReorder,
proxyDecorator: widget.proxyDecorator ?? _proxyDecorator,
autoScroll: widget.autoScroll ??
widget.physics is! NeverScrollableScrollPhysics,
),
),
],
Expand Down

0 comments on commit 6a2c590

Please sign in to comment.