From 779ca5b0b6eab829826a3d97165e2829882793fe Mon Sep 17 00:00:00 2001 From: Julian Bissekkou Date: Fri, 22 May 2020 12:17:14 +0200 Subject: [PATCH 1/3] add option to disable or enable scrolling --- .../ios/Flutter/flutter_export_environment.sh | 10 ++ lib/src/widgets/reorderable_flex.dart | 169 +++++++----------- 2 files changed, 77 insertions(+), 102 deletions(-) create mode 100755 example/ios/Flutter/flutter_export_environment.sh diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh new file mode 100755 index 0000000..dcfdab2 --- /dev/null +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/Users/julianbissekkou/Documents/development/sdk/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/julianbissekkou/Documents/development/tapped/reorderables/example" +export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_BUILD_DIR=build" +export "SYMROOT=${SOURCE_ROOT}/../build/ios" +export "FLUTTER_FRAMEWORK_DIR=/Users/julianbissekkou/Documents/development/sdk/flutter/bin/cache/artifacts/engine/ios" +export "FLUTTER_BUILD_NAME=1.2.0" +export "FLUTTER_BUILD_NUMBER=1.2.0" diff --git a/lib/src/widgets/reorderable_flex.dart b/lib/src/widgets/reorderable_flex.dart index a370740..1409840 100644 --- a/lib/src/widgets/reorderable_flex.dart +++ b/lib/src/widgets/reorderable_flex.dart @@ -7,9 +7,9 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; -import './reorderable_widget.dart'; import './passthrough_overlay.dart'; import './reorderable_mixin.dart'; +import './reorderable_widget.dart'; import './typedefs.dart'; /// Reorderable (drag and drop) version of [Flex], a widget that displays its @@ -53,6 +53,7 @@ class ReorderableFlex extends StatefulWidget { this.scrollController, this.needsLongPressDraggable = true, this.draggingWidgetOpacity = 0.2, + this.isScrollingEnabled = true, }) : assert(direction != null), assert(onReorder != null), assert(children != null), @@ -98,6 +99,8 @@ class ReorderableFlex extends StatefulWidget { final bool needsLongPressDraggable; final double draggingWidgetOpacity; + final bool isScrollingEnabled; + @override _ReorderableFlexState createState() => _ReorderableFlexState(); } @@ -113,8 +116,7 @@ class ReorderableFlex extends StatefulWidget { // insert Draggables into the Overlay above itself. class _ReorderableFlexState extends State { // We use an inner overlay so that the dragging list item doesn't draw outside of the list itself. - final GlobalKey _overlayKey = - GlobalKey(debugLabel: '$ReorderableFlex overlay key'); + final GlobalKey _overlayKey = GlobalKey(debugLabel: '$ReorderableFlex overlay key'); // This entry contains the scrolling list itself. PassthroughOverlayEntry _listOverlayEntry; @@ -140,6 +142,7 @@ class _ReorderableFlexState extends State { scrollController: widget.scrollController, needsLongPressDraggable: widget.needsLongPressDraggable, draggingWidgetOpacity: widget.draggingWidgetOpacity, + isScrollingEnabled: widget.isScrollingEnabled, ); }, ); @@ -147,11 +150,9 @@ class _ReorderableFlexState extends State { @override Widget build(BuildContext context) { - return PassthroughOverlay( - key: _overlayKey, - initialEntries: [ - _listOverlayEntry, - ]); + return PassthroughOverlay(key: _overlayKey, initialEntries: [ + _listOverlayEntry, + ]); } } @@ -173,6 +174,7 @@ class _ReorderableFlexContent extends StatefulWidget { @required this.scrollController, @required this.needsLongPressDraggable, @required this.draggingWidgetOpacity, + @required this.isScrollingEnabled, }); final Widget header; @@ -190,6 +192,7 @@ class _ReorderableFlexContent extends StatefulWidget { final MainAxisAlignment mainAxisAlignment; final bool needsLongPressDraggable; final double draggingWidgetOpacity; + final bool isScrollingEnabled; @override _ReorderableFlexContentState createState() => _ReorderableFlexContentState(); @@ -273,10 +276,8 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> @override void initState() { super.initState(); - _entranceController = AnimationController( - value: 1.0, vsync: this, duration: _reorderAnimationDuration); - _ghostController = AnimationController( - value: 0, vsync: this, duration: _reorderAnimationDuration); + _entranceController = AnimationController(value: 1.0, vsync: this, duration: _reorderAnimationDuration); + _ghostController = AnimationController(value: 0, vsync: this, duration: _reorderAnimationDuration); _entranceController.addStatusListener(_onEntranceStatusChanged); } @@ -287,9 +288,7 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> _attachedScrollPosition = null; } - _scrollController = widget.scrollController ?? - PrimaryScrollController.of(context) ?? - ScrollController(); + _scrollController = widget.scrollController ?? PrimaryScrollController.of(context) ?? ScrollController(); if (!_scrollController.hasClients) { ScrollableState scrollableState = Scrollable.of(context); @@ -347,15 +346,12 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> void _scrollTo(BuildContext context) { if (_scrolling) return; final RenderObject contextObject = context.findRenderObject(); - final RenderAbstractViewport viewport = - RenderAbstractViewport.of(contextObject); + final RenderAbstractViewport viewport = RenderAbstractViewport.of(contextObject); assert(viewport != null); // If and only if the current scroll offset falls in-between the offsets // necessary to reveal the selected context at the top or bottom of the // screen, then it is already on-screen. - final double margin = widget.direction == Axis.horizontal - ? _dropAreaSize.width - : _dropAreaSize.height; + final double margin = widget.direction == Axis.horizontal ? _dropAreaSize.width : _dropAreaSize.height; final double scrollOffset = _scrollController.offset; final double topOffset = max( _scrollController.position.minScrollExtent, @@ -365,8 +361,7 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> _scrollController.position.maxScrollExtent, viewport.getOffsetToReveal(contextObject, 1.0).offset + margin, ); - final bool onScreen = - scrollOffset <= topOffset && scrollOffset >= bottomOffset; + final bool onScreen = scrollOffset <= topOffset && scrollOffset >= bottomOffset; // If the context is off screen, then we request a scroll to make it visible. if (!onScreen) { @@ -390,16 +385,10 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> Widget _buildContainerForMainAxis({List children}) { switch (widget.direction) { case Axis.horizontal: - return Row( - mainAxisSize: MainAxisSize.min, - children: children, - mainAxisAlignment: widget.mainAxisAlignment); + return Row(mainAxisSize: MainAxisSize.min, children: children, mainAxisAlignment: widget.mainAxisAlignment); case Axis.vertical: default: - return Column( - mainAxisSize: MainAxisSize.min, - children: children, - mainAxisAlignment: widget.mainAxisAlignment); + return Column(mainAxisSize: MainAxisSize.min, children: children, mainAxisAlignment: widget.mainAxisAlignment); } } @@ -461,8 +450,7 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> Widget wrapWithSemantics() { // First, determine which semantics actions apply. - final Map semanticsActions = - {}; + final Map semanticsActions = {}; // Create the appropriate semantics actions. void moveToStart() => reorder(index, 0); @@ -472,22 +460,19 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> // before index+2, which is after the space at index+1. void moveAfter() => reorder(index, index + 2); - final MaterialLocalizations localizations = - MaterialLocalizations.of(context); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); if (localizations != null) { // If the item can move to before its current position in the list. if (index > 0) { - semanticsActions[CustomSemanticsAction( - label: localizations.reorderItemToStart)] = moveToStart; + semanticsActions[CustomSemanticsAction(label: localizations.reorderItemToStart)] = moveToStart; String reorderItemBefore = localizations.reorderItemUp; if (widget.direction == Axis.horizontal) { reorderItemBefore = Directionality.of(context) == TextDirection.ltr ? localizations.reorderItemLeft : localizations.reorderItemRight; } - semanticsActions[CustomSemanticsAction(label: reorderItemBefore)] = - moveBefore; + semanticsActions[CustomSemanticsAction(label: reorderItemBefore)] = moveBefore; } // If the item can move to after its current position in the list. @@ -498,10 +483,8 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> ? localizations.reorderItemRight : localizations.reorderItemLeft; } - semanticsActions[CustomSemanticsAction(label: reorderItemAfter)] = - moveAfter; - semanticsActions[CustomSemanticsAction( - label: localizations.reorderItemToEnd)] = moveToEnd; + semanticsActions[CustomSemanticsAction(label: reorderItemAfter)] = moveAfter; + semanticsActions[CustomSemanticsAction(label: localizations.reorderItemToEnd)] = moveToEnd; } } @@ -530,23 +513,29 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> Widget _makeAppearingWidget(Widget child) { return makeAppearingWidget( - child, _entranceController, _draggingFeedbackSize, widget.direction,); + child, + _entranceController, + _draggingFeedbackSize, + widget.direction, + ); } Widget _makeDisappearingWidget(Widget child) { return makeDisappearingWidget( - child, _ghostController, _draggingFeedbackSize, widget.direction,); + child, + _ghostController, + _draggingFeedbackSize, + widget.direction, + ); } - Widget buildDragTarget(BuildContext context, List acceptedCandidates, - List rejectedCandidates) { + Widget buildDragTarget(BuildContext context, List acceptedCandidates, List rejectedCandidates) { final Widget toWrapWithSemantics = wrapWithSemantics(); Widget feedbackBuilder = Builder(builder: (BuildContext context) { // RenderRepaintBoundary renderObject = _contentKey.currentContext.findRenderObject(); // BoxConstraints contentSizeConstraints = BoxConstraints.loose(renderObject.size); - BoxConstraints contentSizeConstraints = BoxConstraints.loose( - _draggingFeedbackSize); //renderObject.constraints + BoxConstraints contentSizeConstraints = BoxConstraints.loose(_draggingFeedbackSize); //renderObject.constraints // debugPrint('${DateTime.now().toString().substring(5, 22)} reorderable_flex.dart(515) $this.buildDragTarget: contentConstraints:$contentSizeConstraints _draggingFeedbackSize:$_draggingFeedbackSize'); return (widget.buildDraggableFeedback ?? defaultBuildDraggableFeedback)( context, contentSizeConstraints, toWrap); @@ -592,15 +581,10 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> // ), // Wrap toWrapWithSemantics with a widget that supports HitTestBehavior // to make sure the whole toWrapWithSemantics responds to pointer events, i.e. dragging - child: MetaData( - child: toWrapWithSemantics, - behavior: HitTestBehavior.opaque), + child: MetaData(child: toWrapWithSemantics, behavior: HitTestBehavior.opaque), //toWrapWithSemantics,//_dragging == toWrap.key ? const SizedBox() : toWrapWithSemantics, childWhenDragging: IgnorePointer( - ignoring: true, - child: Opacity( - opacity: 0, - child: Container(width: 0, height: 0, child: toWrap))), + ignoring: true, child: Opacity(opacity: 0, child: Container(width: 0, height: 0, child: toWrap))), //ConstrainedBox(constraints: contentConstraints),//SizedBox(), dragAnchor: DragAnchor.child, onDragStarted: onDragStarted, @@ -610,8 +594,7 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> // When the drag does not end inside a DragTarget widget, the // drag fails, but we still reorder the widget to the last position it // had been dragged to. - onDraggableCanceled: (Velocity velocity, Offset offset) => - onDragEnded(), + onDraggableCanceled: (Velocity velocity, Offset offset) => onDragEnded(), ) : Draggable( maxSimultaneousDrags: 1, @@ -621,14 +604,9 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> feedback: feedbackBuilder, // Wrap toWrapWithSemantics with a widget that supports HitTestBehavior // to make sure the whole toWrapWithSemantics responds to pointer events, i.e. dragging - child: MetaData( - child: toWrapWithSemantics, - behavior: HitTestBehavior.opaque), + child: MetaData(child: toWrapWithSemantics, behavior: HitTestBehavior.opaque), childWhenDragging: IgnorePointer( - ignoring: true, - child: Opacity( - opacity: 0, - child: Container(width: 0, height: 0, child: toWrap))), + ignoring: true, child: Opacity(opacity: 0, child: Container(width: 0, height: 0, child: toWrap))), dragAnchor: DragAnchor.child, onDragStarted: onDragStarted, // When the drag ends inside a DragTarget widget, the drag @@ -637,8 +615,7 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> // When the drag does not end inside a DragTarget widget, the // drag fails, but we still reorder the widget to the last position it // had been dragged to. - onDraggableCanceled: (Velocity velocity, Offset offset) => - onDragEnded(), + onDraggableCanceled: (Velocity velocity, Offset offset) => onDragEnded(), ); } @@ -711,7 +688,9 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> _requestAnimationToNextIndex(isAcceptingNewTarget: true); }); - _scrollTo(context); + if (widget.isScrollingEnabled) { + _scrollTo(context); + } // If the target is not the original starting point, then we will accept the drop. return willAccept; //_dragging == toAccept && toAccept != toWrap.key; }, @@ -755,38 +734,29 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> //the ghost is moving down, i.e. the tile below the ghost is moving up // debugPrint('index:$index item moving up / ghost moving down'); if (shiftedIndex == _currentIndex && index == _ghostIndex) { - return _buildContainerForMainAxis( - children: [ghostSpacing, dragTarget, entranceSpacing]); + return _buildContainerForMainAxis(children: [ghostSpacing, dragTarget, entranceSpacing]); } else if (shiftedIndex == _currentIndex) { - return _buildContainerForMainAxis( - children: [dragTarget, entranceSpacing]); + return _buildContainerForMainAxis(children: [dragTarget, entranceSpacing]); } else if (index == _ghostIndex) { return _buildContainerForMainAxis( - children: shiftedIndex <= index - ? [dragTarget, ghostSpacing] - : [ghostSpacing, dragTarget]); + children: shiftedIndex <= index ? [dragTarget, ghostSpacing] : [ghostSpacing, dragTarget]); } } else if (_currentIndex < _ghostIndex) { //the ghost is moving up, i.e. the tile above the ghost is moving down // debugPrint('index:$index item moving down / ghost moving up'); if (shiftedIndex == _currentIndex && index == _ghostIndex) { - return _buildContainerForMainAxis( - children: [entranceSpacing, dragTarget, ghostSpacing]); + return _buildContainerForMainAxis(children: [entranceSpacing, dragTarget, ghostSpacing]); } else if (shiftedIndex == _currentIndex) { - return _buildContainerForMainAxis( - children: [entranceSpacing, dragTarget]); + return _buildContainerForMainAxis(children: [entranceSpacing, dragTarget]); } else if (index == _ghostIndex) { return _buildContainerForMainAxis( - children: shiftedIndex >= index - ? [ghostSpacing, dragTarget] - : [dragTarget, ghostSpacing]); + children: shiftedIndex >= index ? [ghostSpacing, dragTarget] : [dragTarget, ghostSpacing]); } } else { // debugPrint('index:$index using _entranceController: spacing on top:${!(_dragStartIndex < _currentIndex)}'); return _buildContainerForMainAxis( - children: _dragStartIndex < _currentIndex - ? [dragTarget, entranceSpacing] - : [entranceSpacing, dragTarget]); + children: + _dragStartIndex < _currentIndex ? [dragTarget, entranceSpacing] : [entranceSpacing, dragTarget]); } } @@ -848,14 +818,12 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> return SingleChildScrollView( // key: _contentKey, scrollDirection: widget.scrollDirection, - child: (widget.buildItemsContainer ?? defaultBuildItemsContainer)( - context, widget.direction, wrappedChildren), + child: (widget.buildItemsContainer ?? defaultBuildItemsContainer)(context, widget.direction, wrappedChildren), padding: widget.padding, controller: _scrollController, ); } else { - return (widget.buildItemsContainer ?? defaultBuildItemsContainer)( - context, widget.direction, wrappedChildren); + return (widget.buildItemsContainer ?? defaultBuildItemsContainer)(context, widget.direction, wrappedChildren); } // }); @@ -876,8 +844,7 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> //// headerRow. //// } // } - Widget defaultBuildItemsContainer( - BuildContext context, Axis direction, List children) { + Widget defaultBuildItemsContainer(BuildContext context, Axis direction, List children) { switch (direction) { case Axis.horizontal: return Row(children: children); @@ -887,14 +854,12 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> } } - Widget defaultBuildDraggableFeedback( - BuildContext context, BoxConstraints constraints, Widget child) { + Widget defaultBuildDraggableFeedback(BuildContext context, BoxConstraints constraints, Widget child) { return Transform( transform: Matrix4.rotationZ(0), alignment: FractionalOffset.topLeft, child: Material( - child: - Card(child: ConstrainedBox(constraints: constraints, child: child)), + child: Card(child: ConstrainedBox(constraints: constraints, child: child)), elevation: 6.0, color: Colors.transparent, borderRadius: BorderRadius.zero, @@ -947,8 +912,8 @@ class ReorderableRow extends ReorderableFlex { ScrollController scrollController, bool needsLongPressDraggable = true, double draggingWidgetOpacity = 0.2, - }) - : super( + bool isScrollingEnabled = true, + }) : super( key: key, header: header, footer: footer, @@ -958,8 +923,7 @@ class ReorderableRow extends ReorderableFlex { direction: Axis.horizontal, scrollDirection: Axis.horizontal, padding: padding, - buildItemsContainer: - (BuildContext context, Axis direction, List children) { + buildItemsContainer: (BuildContext context, Axis direction, List children) { return Flex( direction: direction, mainAxisAlignment: mainAxisAlignment, @@ -975,6 +939,7 @@ class ReorderableRow extends ReorderableFlex { scrollController: scrollController, needsLongPressDraggable: needsLongPressDraggable, draggingWidgetOpacity: draggingWidgetOpacity, + isScrollingEnabled: isScrollingEnabled, ); } @@ -1022,8 +987,8 @@ class ReorderableColumn extends ReorderableFlex { ScrollController scrollController, bool needsLongPressDraggable = true, double draggingWidgetOpacity = 0.2, - }) - : super( + bool isScrollingEnabled = true, + }) : super( key: key, header: header, footer: footer, @@ -1032,8 +997,7 @@ class ReorderableColumn extends ReorderableFlex { onNoReorder: onNoReorder, direction: Axis.vertical, padding: padding, - buildItemsContainer: - (BuildContext context, Axis direction, List children) { + buildItemsContainer: (BuildContext context, Axis direction, List children) { return Flex( direction: direction, mainAxisAlignment: mainAxisAlignment, @@ -1049,5 +1013,6 @@ class ReorderableColumn extends ReorderableFlex { scrollController: scrollController, needsLongPressDraggable: needsLongPressDraggable, draggingWidgetOpacity: draggingWidgetOpacity, + isScrollingEnabled: isScrollingEnabled, ); } From 6bba9997d155d6bcba8dab96bddd56cf1eac89b5 Mon Sep 17 00:00:00 2001 From: Julian Bissekkou Date: Fri, 22 May 2020 14:23:40 +0200 Subject: [PATCH 2/3] .gitignore fix --- .gitignore | 2 ++ example/ios/Flutter/flutter_export_environment.sh | 10 ---------- 2 files changed, 2 insertions(+), 10 deletions(-) delete mode 100755 example/ios/Flutter/flutter_export_environment.sh diff --git a/.gitignore b/.gitignore index 47e0b4d..4f4860e 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,5 @@ build/ !**/ios/**/default.pbxuser !**/ios/**/default.perspectivev3 !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages + +flutter_export_environment.sh \ No newline at end of file diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh deleted file mode 100755 index dcfdab2..0000000 --- a/example/ios/Flutter/flutter_export_environment.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=/Users/julianbissekkou/Documents/development/sdk/flutter" -export "FLUTTER_APPLICATION_PATH=/Users/julianbissekkou/Documents/development/tapped/reorderables/example" -export "FLUTTER_TARGET=lib/main.dart" -export "FLUTTER_BUILD_DIR=build" -export "SYMROOT=${SOURCE_ROOT}/../build/ios" -export "FLUTTER_FRAMEWORK_DIR=/Users/julianbissekkou/Documents/development/sdk/flutter/bin/cache/artifacts/engine/ios" -export "FLUTTER_BUILD_NAME=1.2.0" -export "FLUTTER_BUILD_NUMBER=1.2.0" From 246cf79cce7022ef2ce989c59117013689e38b8c Mon Sep 17 00:00:00 2001 From: Julian Bissekkou Date: Fri, 22 May 2020 14:26:16 +0200 Subject: [PATCH 3/3] reformat code --- lib/src/widgets/reorderable_flex.dart | 138 ++++++++++++++++++-------- 1 file changed, 96 insertions(+), 42 deletions(-) diff --git a/lib/src/widgets/reorderable_flex.dart b/lib/src/widgets/reorderable_flex.dart index 1409840..66b29ef 100644 --- a/lib/src/widgets/reorderable_flex.dart +++ b/lib/src/widgets/reorderable_flex.dart @@ -116,7 +116,8 @@ class ReorderableFlex extends StatefulWidget { // insert Draggables into the Overlay above itself. class _ReorderableFlexState extends State { // We use an inner overlay so that the dragging list item doesn't draw outside of the list itself. - final GlobalKey _overlayKey = GlobalKey(debugLabel: '$ReorderableFlex overlay key'); + final GlobalKey _overlayKey = + GlobalKey(debugLabel: '$ReorderableFlex overlay key'); // This entry contains the scrolling list itself. PassthroughOverlayEntry _listOverlayEntry; @@ -150,9 +151,11 @@ class _ReorderableFlexState extends State { @override Widget build(BuildContext context) { - return PassthroughOverlay(key: _overlayKey, initialEntries: [ - _listOverlayEntry, - ]); + return PassthroughOverlay( + key: _overlayKey, + initialEntries: [ + _listOverlayEntry, + ]); } } @@ -276,8 +279,10 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> @override void initState() { super.initState(); - _entranceController = AnimationController(value: 1.0, vsync: this, duration: _reorderAnimationDuration); - _ghostController = AnimationController(value: 0, vsync: this, duration: _reorderAnimationDuration); + _entranceController = AnimationController( + value: 1.0, vsync: this, duration: _reorderAnimationDuration); + _ghostController = AnimationController( + value: 0, vsync: this, duration: _reorderAnimationDuration); _entranceController.addStatusListener(_onEntranceStatusChanged); } @@ -288,7 +293,9 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> _attachedScrollPosition = null; } - _scrollController = widget.scrollController ?? PrimaryScrollController.of(context) ?? ScrollController(); + _scrollController = widget.scrollController ?? + PrimaryScrollController.of(context) ?? + ScrollController(); if (!_scrollController.hasClients) { ScrollableState scrollableState = Scrollable.of(context); @@ -346,12 +353,15 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> void _scrollTo(BuildContext context) { if (_scrolling) return; final RenderObject contextObject = context.findRenderObject(); - final RenderAbstractViewport viewport = RenderAbstractViewport.of(contextObject); + final RenderAbstractViewport viewport = + RenderAbstractViewport.of(contextObject); assert(viewport != null); // If and only if the current scroll offset falls in-between the offsets // necessary to reveal the selected context at the top or bottom of the // screen, then it is already on-screen. - final double margin = widget.direction == Axis.horizontal ? _dropAreaSize.width : _dropAreaSize.height; + final double margin = widget.direction == Axis.horizontal + ? _dropAreaSize.width + : _dropAreaSize.height; final double scrollOffset = _scrollController.offset; final double topOffset = max( _scrollController.position.minScrollExtent, @@ -361,7 +371,8 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> _scrollController.position.maxScrollExtent, viewport.getOffsetToReveal(contextObject, 1.0).offset + margin, ); - final bool onScreen = scrollOffset <= topOffset && scrollOffset >= bottomOffset; + final bool onScreen = + scrollOffset <= topOffset && scrollOffset >= bottomOffset; // If the context is off screen, then we request a scroll to make it visible. if (!onScreen) { @@ -385,10 +396,16 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> Widget _buildContainerForMainAxis({List children}) { switch (widget.direction) { case Axis.horizontal: - return Row(mainAxisSize: MainAxisSize.min, children: children, mainAxisAlignment: widget.mainAxisAlignment); + return Row( + mainAxisSize: MainAxisSize.min, + children: children, + mainAxisAlignment: widget.mainAxisAlignment); case Axis.vertical: default: - return Column(mainAxisSize: MainAxisSize.min, children: children, mainAxisAlignment: widget.mainAxisAlignment); + return Column( + mainAxisSize: MainAxisSize.min, + children: children, + mainAxisAlignment: widget.mainAxisAlignment); } } @@ -450,7 +467,8 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> Widget wrapWithSemantics() { // First, determine which semantics actions apply. - final Map semanticsActions = {}; + final Map semanticsActions = + {}; // Create the appropriate semantics actions. void moveToStart() => reorder(index, 0); @@ -460,19 +478,22 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> // before index+2, which is after the space at index+1. void moveAfter() => reorder(index, index + 2); - final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final MaterialLocalizations localizations = + MaterialLocalizations.of(context); if (localizations != null) { // If the item can move to before its current position in the list. if (index > 0) { - semanticsActions[CustomSemanticsAction(label: localizations.reorderItemToStart)] = moveToStart; + semanticsActions[CustomSemanticsAction( + label: localizations.reorderItemToStart)] = moveToStart; String reorderItemBefore = localizations.reorderItemUp; if (widget.direction == Axis.horizontal) { reorderItemBefore = Directionality.of(context) == TextDirection.ltr ? localizations.reorderItemLeft : localizations.reorderItemRight; } - semanticsActions[CustomSemanticsAction(label: reorderItemBefore)] = moveBefore; + semanticsActions[CustomSemanticsAction(label: reorderItemBefore)] = + moveBefore; } // If the item can move to after its current position in the list. @@ -483,8 +504,10 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> ? localizations.reorderItemRight : localizations.reorderItemLeft; } - semanticsActions[CustomSemanticsAction(label: reorderItemAfter)] = moveAfter; - semanticsActions[CustomSemanticsAction(label: localizations.reorderItemToEnd)] = moveToEnd; + semanticsActions[CustomSemanticsAction(label: reorderItemAfter)] = + moveAfter; + semanticsActions[CustomSemanticsAction( + label: localizations.reorderItemToEnd)] = moveToEnd; } } @@ -529,13 +552,15 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> ); } - Widget buildDragTarget(BuildContext context, List acceptedCandidates, List rejectedCandidates) { + Widget buildDragTarget(BuildContext context, List acceptedCandidates, + List rejectedCandidates) { final Widget toWrapWithSemantics = wrapWithSemantics(); Widget feedbackBuilder = Builder(builder: (BuildContext context) { // RenderRepaintBoundary renderObject = _contentKey.currentContext.findRenderObject(); // BoxConstraints contentSizeConstraints = BoxConstraints.loose(renderObject.size); - BoxConstraints contentSizeConstraints = BoxConstraints.loose(_draggingFeedbackSize); //renderObject.constraints + BoxConstraints contentSizeConstraints = BoxConstraints.loose( + _draggingFeedbackSize); //renderObject.constraints // debugPrint('${DateTime.now().toString().substring(5, 22)} reorderable_flex.dart(515) $this.buildDragTarget: contentConstraints:$contentSizeConstraints _draggingFeedbackSize:$_draggingFeedbackSize'); return (widget.buildDraggableFeedback ?? defaultBuildDraggableFeedback)( context, contentSizeConstraints, toWrap); @@ -581,10 +606,15 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> // ), // Wrap toWrapWithSemantics with a widget that supports HitTestBehavior // to make sure the whole toWrapWithSemantics responds to pointer events, i.e. dragging - child: MetaData(child: toWrapWithSemantics, behavior: HitTestBehavior.opaque), + child: MetaData( + child: toWrapWithSemantics, + behavior: HitTestBehavior.opaque), //toWrapWithSemantics,//_dragging == toWrap.key ? const SizedBox() : toWrapWithSemantics, childWhenDragging: IgnorePointer( - ignoring: true, child: Opacity(opacity: 0, child: Container(width: 0, height: 0, child: toWrap))), + ignoring: true, + child: Opacity( + opacity: 0, + child: Container(width: 0, height: 0, child: toWrap))), //ConstrainedBox(constraints: contentConstraints),//SizedBox(), dragAnchor: DragAnchor.child, onDragStarted: onDragStarted, @@ -594,7 +624,8 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> // When the drag does not end inside a DragTarget widget, the // drag fails, but we still reorder the widget to the last position it // had been dragged to. - onDraggableCanceled: (Velocity velocity, Offset offset) => onDragEnded(), + onDraggableCanceled: (Velocity velocity, Offset offset) => + onDragEnded(), ) : Draggable( maxSimultaneousDrags: 1, @@ -604,9 +635,14 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> feedback: feedbackBuilder, // Wrap toWrapWithSemantics with a widget that supports HitTestBehavior // to make sure the whole toWrapWithSemantics responds to pointer events, i.e. dragging - child: MetaData(child: toWrapWithSemantics, behavior: HitTestBehavior.opaque), + child: MetaData( + child: toWrapWithSemantics, + behavior: HitTestBehavior.opaque), childWhenDragging: IgnorePointer( - ignoring: true, child: Opacity(opacity: 0, child: Container(width: 0, height: 0, child: toWrap))), + ignoring: true, + child: Opacity( + opacity: 0, + child: Container(width: 0, height: 0, child: toWrap))), dragAnchor: DragAnchor.child, onDragStarted: onDragStarted, // When the drag ends inside a DragTarget widget, the drag @@ -615,7 +651,8 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> // When the drag does not end inside a DragTarget widget, the // drag fails, but we still reorder the widget to the last position it // had been dragged to. - onDraggableCanceled: (Velocity velocity, Offset offset) => onDragEnded(), + onDraggableCanceled: (Velocity velocity, Offset offset) => + onDragEnded(), ); } @@ -703,7 +740,8 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> // Determine the size of the drop area to show under the dragging widget. Widget spacing = _draggingWidget == null ? SizedBox.fromSize(size: _dropAreaSize) - : Opacity(opacity: widget.draggingWidgetOpacity, child: _draggingWidget); + : Opacity( + opacity: widget.draggingWidgetOpacity, child: _draggingWidget); // Widget spacing = SizedBox.fromSize( // size: _dropAreaSize, // child: _draggingWidget != null ? Opacity(opacity: 0.2, child: _draggingWidget) : null, @@ -734,29 +772,38 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> //the ghost is moving down, i.e. the tile below the ghost is moving up // debugPrint('index:$index item moving up / ghost moving down'); if (shiftedIndex == _currentIndex && index == _ghostIndex) { - return _buildContainerForMainAxis(children: [ghostSpacing, dragTarget, entranceSpacing]); + return _buildContainerForMainAxis( + children: [ghostSpacing, dragTarget, entranceSpacing]); } else if (shiftedIndex == _currentIndex) { - return _buildContainerForMainAxis(children: [dragTarget, entranceSpacing]); + return _buildContainerForMainAxis( + children: [dragTarget, entranceSpacing]); } else if (index == _ghostIndex) { return _buildContainerForMainAxis( - children: shiftedIndex <= index ? [dragTarget, ghostSpacing] : [ghostSpacing, dragTarget]); + children: shiftedIndex <= index + ? [dragTarget, ghostSpacing] + : [ghostSpacing, dragTarget]); } } else if (_currentIndex < _ghostIndex) { //the ghost is moving up, i.e. the tile above the ghost is moving down // debugPrint('index:$index item moving down / ghost moving up'); if (shiftedIndex == _currentIndex && index == _ghostIndex) { - return _buildContainerForMainAxis(children: [entranceSpacing, dragTarget, ghostSpacing]); + return _buildContainerForMainAxis( + children: [entranceSpacing, dragTarget, ghostSpacing]); } else if (shiftedIndex == _currentIndex) { - return _buildContainerForMainAxis(children: [entranceSpacing, dragTarget]); + return _buildContainerForMainAxis( + children: [entranceSpacing, dragTarget]); } else if (index == _ghostIndex) { return _buildContainerForMainAxis( - children: shiftedIndex >= index ? [ghostSpacing, dragTarget] : [dragTarget, ghostSpacing]); + children: shiftedIndex >= index + ? [ghostSpacing, dragTarget] + : [dragTarget, ghostSpacing]); } } else { // debugPrint('index:$index using _entranceController: spacing on top:${!(_dragStartIndex < _currentIndex)}'); return _buildContainerForMainAxis( - children: - _dragStartIndex < _currentIndex ? [dragTarget, entranceSpacing] : [entranceSpacing, dragTarget]); + children: _dragStartIndex < _currentIndex + ? [dragTarget, entranceSpacing] + : [entranceSpacing, dragTarget]); } } @@ -818,12 +865,14 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> return SingleChildScrollView( // key: _contentKey, scrollDirection: widget.scrollDirection, - child: (widget.buildItemsContainer ?? defaultBuildItemsContainer)(context, widget.direction, wrappedChildren), + child: (widget.buildItemsContainer ?? defaultBuildItemsContainer)( + context, widget.direction, wrappedChildren), padding: widget.padding, controller: _scrollController, ); } else { - return (widget.buildItemsContainer ?? defaultBuildItemsContainer)(context, widget.direction, wrappedChildren); + return (widget.buildItemsContainer ?? defaultBuildItemsContainer)( + context, widget.direction, wrappedChildren); } // }); @@ -844,7 +893,8 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> //// headerRow. //// } // } - Widget defaultBuildItemsContainer(BuildContext context, Axis direction, List children) { + Widget defaultBuildItemsContainer( + BuildContext context, Axis direction, List children) { switch (direction) { case Axis.horizontal: return Row(children: children); @@ -854,12 +904,14 @@ class _ReorderableFlexContentState extends State<_ReorderableFlexContent> } } - Widget defaultBuildDraggableFeedback(BuildContext context, BoxConstraints constraints, Widget child) { + Widget defaultBuildDraggableFeedback( + BuildContext context, BoxConstraints constraints, Widget child) { return Transform( transform: Matrix4.rotationZ(0), alignment: FractionalOffset.topLeft, child: Material( - child: Card(child: ConstrainedBox(constraints: constraints, child: child)), + child: + Card(child: ConstrainedBox(constraints: constraints, child: child)), elevation: 6.0, color: Colors.transparent, borderRadius: BorderRadius.zero, @@ -923,7 +975,8 @@ class ReorderableRow extends ReorderableFlex { direction: Axis.horizontal, scrollDirection: Axis.horizontal, padding: padding, - buildItemsContainer: (BuildContext context, Axis direction, List children) { + buildItemsContainer: + (BuildContext context, Axis direction, List children) { return Flex( direction: direction, mainAxisAlignment: mainAxisAlignment, @@ -997,7 +1050,8 @@ class ReorderableColumn extends ReorderableFlex { onNoReorder: onNoReorder, direction: Axis.vertical, padding: padding, - buildItemsContainer: (BuildContext context, Axis direction, List children) { + buildItemsContainer: + (BuildContext context, Axis direction, List children) { return Flex( direction: direction, mainAxisAlignment: mainAxisAlignment,