From c267e19ec6cb96f394931e0a3f1be276b3dffc6c Mon Sep 17 00:00:00 2001 From: Lee JunHo Date: Wed, 2 Dec 2020 22:04:23 +0900 Subject: [PATCH] Sets whether the children are reorderable or not --- lib/src/widgets/reorderable_flex.dart | 17 +++++++++++++++-- lib/src/widgets/reorderable_sliver.dart | 2 +- lib/src/widgets/reorderable_table.dart | 5 +++++ lib/src/widgets/reorderable_wrap.dart | 13 +++++++++++-- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/src/widgets/reorderable_flex.dart b/lib/src/widgets/reorderable_flex.dart index cde4362..994d5aa 100644 --- a/lib/src/widgets/reorderable_flex.dart +++ b/lib/src/widgets/reorderable_flex.dart @@ -53,6 +53,7 @@ class ReorderableFlex extends StatefulWidget { this.scrollController, this.needsLongPressDraggable = true, this.draggingWidgetOpacity = 0.2, + this.enabled = true, }) : assert(direction != null), assert(onReorder != null), assert(children != null), @@ -98,6 +99,9 @@ class ReorderableFlex extends StatefulWidget { final bool needsLongPressDraggable; final double draggingWidgetOpacity; + /// Sets whether the children are reorderable or not + final bool enabled; + @override _ReorderableFlexState createState() => _ReorderableFlexState(); } @@ -140,6 +144,7 @@ class _ReorderableFlexState extends State { scrollController: widget.scrollController, needsLongPressDraggable: widget.needsLongPressDraggable, draggingWidgetOpacity: widget.draggingWidgetOpacity, + enabled: widget.enabled, ); }, ); @@ -173,6 +178,7 @@ class _ReorderableFlexContent extends StatefulWidget { @required this.scrollController, @required this.needsLongPressDraggable, @required this.draggingWidgetOpacity, + @required this.enabled, }); final Widget header; @@ -191,6 +197,9 @@ class _ReorderableFlexContent extends StatefulWidget { final bool needsLongPressDraggable; final double draggingWidgetOpacity; + /// Sets whether the children are reorderable or not + final bool enabled; + @override _ReorderableFlexContentState createState() => _ReorderableFlexContentState(); } @@ -574,7 +583,7 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> } else { child = widget.needsLongPressDraggable ? LongPressDraggable( - maxSimultaneousDrags: 1, + maxSimultaneousDrags: widget.enabled? 1 : 0, axis: widget.direction, data: toWrap.key, ignoringFeedbackSemantics: false, @@ -622,7 +631,7 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> onDragEnded(), ) : Draggable( - maxSimultaneousDrags: 1, + maxSimultaneousDrags: widget.enabled? 1 : 0, axis: widget.direction, data: toWrap.key, ignoringFeedbackSemantics: false, @@ -956,6 +965,7 @@ class ReorderableRow extends ReorderableFlex { ScrollController scrollController, bool needsLongPressDraggable = true, double draggingWidgetOpacity = 0.2, + bool enabled = true, }) : super( key: key, header: header, @@ -983,6 +993,7 @@ class ReorderableRow extends ReorderableFlex { scrollController: scrollController, needsLongPressDraggable: needsLongPressDraggable, draggingWidgetOpacity: draggingWidgetOpacity, + enabled: enabled, ); } @@ -1030,6 +1041,7 @@ class ReorderableColumn extends ReorderableFlex { ScrollController scrollController, bool needsLongPressDraggable = true, double draggingWidgetOpacity = 0.2, + bool enabled = true, }) : super( key: key, header: header, @@ -1056,5 +1068,6 @@ class ReorderableColumn extends ReorderableFlex { scrollController: scrollController, needsLongPressDraggable: needsLongPressDraggable, draggingWidgetOpacity: draggingWidgetOpacity, + enabled: enabled, ); } diff --git a/lib/src/widgets/reorderable_sliver.dart b/lib/src/widgets/reorderable_sliver.dart index f9cf789..df3b256 100644 --- a/lib/src/widgets/reorderable_sliver.dart +++ b/lib/src/widgets/reorderable_sliver.dart @@ -757,7 +757,7 @@ class _ReorderableSliverListState extends State // We build the draggable inside of a layout builder so that we can // constrain the size of the feedback dragging widget. child = LongPressDraggable( - maxSimultaneousDrags: widget.enabled?1:0, + maxSimultaneousDrags: widget.enabled? 1 : 0, axis: Axis.vertical, //widget.direction, data: index, diff --git a/lib/src/widgets/reorderable_table.dart b/lib/src/widgets/reorderable_table.dart index 2ce3c88..76f9495 100644 --- a/lib/src/widgets/reorderable_table.dart +++ b/lib/src/widgets/reorderable_table.dart @@ -66,6 +66,7 @@ class ReorderableTable extends StatelessWidget { this.textBaseline, this.header, this.footer, + this.enabled = true, @required this.onReorder, this.decorateDraggableFeedback, this.onNoReorder, @@ -172,6 +173,9 @@ class ReorderableTable extends StatelessWidget { /// alignment of columns. final Widget footer; + /// Sets whether the children are reorderable or not + final bool enabled; + /// Called when a child is dropped into a new position to shuffle the /// children. final ReorderCallback onReorder; @@ -198,6 +202,7 @@ class ReorderableTable extends StatelessWidget { onReorder: onReorder, onNoReorder: onNoReorder, direction: Axis.vertical, + enabled: enabled, buildItemsContainer: (BuildContext containerContext, Axis direction, List children) { return TabluarFlex( diff --git a/lib/src/widgets/reorderable_wrap.dart b/lib/src/widgets/reorderable_wrap.dart index acb4a11..95a8329 100644 --- a/lib/src/widgets/reorderable_wrap.dart +++ b/lib/src/widgets/reorderable_wrap.dart @@ -55,6 +55,7 @@ class ReorderableWrap extends StatefulWidget { this.verticalDirection = VerticalDirection.down, this.minMainAxisCount, this.maxMainAxisCount, + this.enabled = true, this.onNoReorder, this.onReorderStarted, }) : assert(direction != null), @@ -234,6 +235,9 @@ class ReorderableWrap extends StatefulWidget { final int minMainAxisCount; final int maxMainAxisCount; + /// Sets whether the children are reorderable or not + final bool enabled; + @override _ReorderableWrapState createState() => _ReorderableWrapState(); } @@ -284,6 +288,7 @@ class _ReorderableWrapState extends State { minMainAxisCount: widget.minMainAxisCount, maxMainAxisCount: widget.maxMainAxisCount, controller: widget.controller, + enabled: widget.enabled, ); }, ); @@ -325,6 +330,7 @@ class _ReorderableWrapContent extends StatefulWidget { @required this.verticalDirection, @required this.minMainAxisCount, @required this.maxMainAxisCount, + @required this.enabled, }); final List header; @@ -351,6 +357,9 @@ class _ReorderableWrapContent extends StatefulWidget { final int minMainAxisCount; final int maxMainAxisCount; + /// Sets whether the children are reorderable or not + final bool enabled; + @override _ReorderableWrapContentState createState() => _ReorderableWrapContentState(); } @@ -787,7 +796,7 @@ class _ReorderableWrapContentState extends State<_ReorderableWrapContent> // constrain the size of the feedback dragging widget. child = this.widget.needsLongPressDraggable ? LongPressDraggable( - maxSimultaneousDrags: 1, + maxSimultaneousDrags: widget.enabled ? 1 : 0, data: index, //toWrap.key, ignoringFeedbackSemantics: false, feedback: feedbackBuilder, @@ -816,7 +825,7 @@ class _ReorderableWrapContentState extends State<_ReorderableWrapContent> onDragEnded(), ) : Draggable( - maxSimultaneousDrags: 1, + maxSimultaneousDrags: widget.enabled ? 1 : 0, data: index, //toWrap.key, ignoringFeedbackSemantics: false, feedback: feedbackBuilder,