|
@@ -1,3 +1,5 @@
|
|
|
|
+import 'dart:async';
|
|
|
|
+
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
import '../../utils/log.dart';
|
|
import '../../utils/log.dart';
|
|
@@ -8,6 +10,8 @@ import 'reorder_flex.dart';
|
|
/// [DragTargetInterceptor] is used to intercept the [DragTarget]'s
|
|
/// [DragTargetInterceptor] is used to intercept the [DragTarget]'s
|
|
/// [onWillAccept], [OnAccept], and [onLeave] event.
|
|
/// [onWillAccept], [OnAccept], and [onLeave] event.
|
|
abstract class DragTargetInterceptor {
|
|
abstract class DragTargetInterceptor {
|
|
|
|
+ String get reorderFlexId;
|
|
|
|
+
|
|
/// Returns [yes] to receive the [DragTarget]'s event.
|
|
/// Returns [yes] to receive the [DragTarget]'s event.
|
|
bool canHandler(FlexDragTargetData dragTargetData);
|
|
bool canHandler(FlexDragTargetData dragTargetData);
|
|
|
|
|
|
@@ -37,7 +41,7 @@ abstract class OverlapDragTargetDelegate {
|
|
int dragTargetIndex,
|
|
int dragTargetIndex,
|
|
);
|
|
);
|
|
|
|
|
|
- bool canMoveTo(String dragTargetId);
|
|
|
|
|
|
+ int canMoveTo(String dragTargetId);
|
|
}
|
|
}
|
|
|
|
|
|
/// [OverlappingDragTargetInterceptor] is used to receive the overlapping
|
|
/// [OverlappingDragTargetInterceptor] is used to receive the overlapping
|
|
@@ -47,6 +51,7 @@ abstract class OverlapDragTargetDelegate {
|
|
/// Receive the [DragTarget] event if the [acceptedReorderFlexId] contains
|
|
/// Receive the [DragTarget] event if the [acceptedReorderFlexId] contains
|
|
/// the passed in dragTarget' reorderFlexId.
|
|
/// the passed in dragTarget' reorderFlexId.
|
|
class OverlappingDragTargetInterceptor extends DragTargetInterceptor {
|
|
class OverlappingDragTargetInterceptor extends DragTargetInterceptor {
|
|
|
|
+ @override
|
|
final String reorderFlexId;
|
|
final String reorderFlexId;
|
|
final List<String> acceptedReorderFlexId;
|
|
final List<String> acceptedReorderFlexId;
|
|
final OverlapDragTargetDelegate delegate;
|
|
final OverlapDragTargetDelegate delegate;
|
|
@@ -72,8 +77,11 @@ class OverlappingDragTargetInterceptor extends DragTargetInterceptor {
|
|
if (dragTargetId == dragTargetData.reorderFlexId) {
|
|
if (dragTargetId == dragTargetData.reorderFlexId) {
|
|
delegate.cancel();
|
|
delegate.cancel();
|
|
} else {
|
|
} else {
|
|
- if (delegate.canMoveTo(dragTargetId)) {
|
|
|
|
- delegate.moveTo(dragTargetId, dragTargetData, 0);
|
|
|
|
|
|
+ final index = delegate.canMoveTo(dragTargetId);
|
|
|
|
+ Log.trace(
|
|
|
|
+ '[$OverlappingDragTargetInterceptor] move to $dragTargetId at $index');
|
|
|
|
+ if (index != -1) {
|
|
|
|
+ delegate.moveTo(dragTargetId, dragTargetData, index);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -96,6 +104,7 @@ abstract class CrossReorderFlexDragTargetDelegate {
|
|
}
|
|
}
|
|
|
|
|
|
class CrossReorderFlexDragTargetInterceptor extends DragTargetInterceptor {
|
|
class CrossReorderFlexDragTargetInterceptor extends DragTargetInterceptor {
|
|
|
|
+ @override
|
|
final String reorderFlexId;
|
|
final String reorderFlexId;
|
|
final List<String> acceptedReorderFlexIds;
|
|
final List<String> acceptedReorderFlexIds;
|
|
final CrossReorderFlexDragTargetDelegate delegate;
|
|
final CrossReorderFlexDragTargetDelegate delegate;
|
|
@@ -119,8 +128,12 @@ class CrossReorderFlexDragTargetInterceptor extends DragTargetInterceptor {
|
|
/// If the columnId equal to the dragTargetData's columnId,
|
|
/// If the columnId equal to the dragTargetData's columnId,
|
|
/// it means the dragTarget is dragging on the top of its own list.
|
|
/// it means the dragTarget is dragging on the top of its own list.
|
|
/// Otherwise, it means the dargTarget was moved to another list.
|
|
/// Otherwise, it means the dargTarget was moved to another list.
|
|
|
|
+ Log.trace(
|
|
|
|
+ "[$CrossReorderFlexDragTargetInterceptor] $reorderFlexId accept ${dragTargetData.reorderFlexId} ${reorderFlexId != dragTargetData.reorderFlexId}");
|
|
return reorderFlexId != dragTargetData.reorderFlexId;
|
|
return reorderFlexId != dragTargetData.reorderFlexId;
|
|
} else {
|
|
} else {
|
|
|
|
+ Log.trace(
|
|
|
|
+ "[$CrossReorderFlexDragTargetInterceptor] not accept ${dragTargetData.reorderFlexId}");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -151,6 +164,9 @@ class CrossReorderFlexDragTargetInterceptor extends DragTargetInterceptor {
|
|
dragTargetIndex,
|
|
dragTargetIndex,
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ Log.debug(
|
|
|
|
+ '[$CrossReorderFlexDragTargetInterceptor] dargTargetIndex: $dragTargetIndex, reorderFlexId: $reorderFlexId');
|
|
|
|
+
|
|
if (isNewDragTarget == false) {
|
|
if (isNewDragTarget == false) {
|
|
delegate.updateDragTargetData(reorderFlexId, dragTargetIndex);
|
|
delegate.updateDragTargetData(reorderFlexId, dragTargetIndex);
|
|
reorderFlexState.handleOnWillAccept(context, dragTargetIndex);
|
|
reorderFlexState.handleOnWillAccept(context, dragTargetIndex);
|