|
@@ -13,7 +13,8 @@ typedef OnDragEnded = void Function();
|
|
typedef OnReorder = void Function(int fromIndex, int toIndex);
|
|
typedef OnReorder = void Function(int fromIndex, int toIndex);
|
|
typedef OnDeleted = void Function(int deletedIndex);
|
|
typedef OnDeleted = void Function(int deletedIndex);
|
|
typedef OnInserted = void Function(int insertedIndex);
|
|
typedef OnInserted = void Function(int insertedIndex);
|
|
-typedef OnReveivePassedInPhantom = void Function(FlexDragTargetData dragTargetData, int phantomIndex);
|
|
|
|
|
|
+typedef OnReveivePassedInPhantom = void Function(
|
|
|
|
+ FlexDragTargetData dragTargetData, int phantomIndex);
|
|
|
|
|
|
abstract class ReoderFlextDataSource {
|
|
abstract class ReoderFlextDataSource {
|
|
String get identifier;
|
|
String get identifier;
|
|
@@ -32,7 +33,7 @@ class ReorderFlexConfig {
|
|
const ReorderFlexConfig();
|
|
const ReorderFlexConfig();
|
|
}
|
|
}
|
|
|
|
|
|
-class ReorderFlex extends StatefulWidget with DraggingReorderFlex {
|
|
|
|
|
|
+class ReorderFlex extends StatefulWidget {
|
|
final ReorderFlexConfig config;
|
|
final ReorderFlexConfig config;
|
|
|
|
|
|
final List<Widget> children;
|
|
final List<Widget> children;
|
|
@@ -68,16 +69,11 @@ class ReorderFlex extends StatefulWidget with DraggingReorderFlex {
|
|
@override
|
|
@override
|
|
State<ReorderFlex> createState() => ReorderFlexState();
|
|
State<ReorderFlex> createState() => ReorderFlexState();
|
|
|
|
|
|
- @override
|
|
|
|
String get reorderFlexId => dataSource.identifier;
|
|
String get reorderFlexId => dataSource.identifier;
|
|
-
|
|
|
|
- @override
|
|
|
|
- ReoderFlexItem itemAtIndex(int index) {
|
|
|
|
- return dataSource.items[index];
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-class ReorderFlexState extends State<ReorderFlex> with ReorderFlexMinxi, TickerProviderStateMixin<ReorderFlex> {
|
|
|
|
|
|
+class ReorderFlexState extends State<ReorderFlex>
|
|
|
|
+ with ReorderFlexMinxi, TickerProviderStateMixin<ReorderFlex> {
|
|
/// Controls scrolls and measures scroll progress.
|
|
/// Controls scrolls and measures scroll progress.
|
|
late ScrollController _scrollController;
|
|
late ScrollController _scrollController;
|
|
ScrollPosition? _attachedScrollPosition;
|
|
ScrollPosition? _attachedScrollPosition;
|
|
@@ -113,7 +109,9 @@ class ReorderFlexState extends State<ReorderFlex> with ReorderFlexMinxi, TickerP
|
|
_attachedScrollPosition = null;
|
|
_attachedScrollPosition = null;
|
|
}
|
|
}
|
|
|
|
|
|
- _scrollController = widget.scrollController ?? PrimaryScrollController.of(context) ?? ScrollController();
|
|
|
|
|
|
+ _scrollController = widget.scrollController ??
|
|
|
|
+ PrimaryScrollController.of(context) ??
|
|
|
|
+ ScrollController();
|
|
|
|
|
|
if (_scrollController.hasClients) {
|
|
if (_scrollController.hasClients) {
|
|
_attachedScrollPosition = Scrollable.of(context)?.position;
|
|
_attachedScrollPosition = Scrollable.of(context)?.position;
|
|
@@ -235,7 +233,9 @@ class ReorderFlexState extends State<ReorderFlex> with ReorderFlexMinxi, TickerP
|
|
]);
|
|
]);
|
|
} else if (childIndex == dragPhantomIndex) {
|
|
} else if (childIndex == dragPhantomIndex) {
|
|
return _buildDraggingContainer(
|
|
return _buildDraggingContainer(
|
|
- children: shiftedIndex <= childIndex ? [dragTarget, disappearSpace] : [disappearSpace, dragTarget]);
|
|
|
|
|
|
+ children: shiftedIndex <= childIndex
|
|
|
|
+ ? [dragTarget, disappearSpace]
|
|
|
|
+ : [disappearSpace, dragTarget]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -256,7 +256,9 @@ class ReorderFlexState extends State<ReorderFlex> with ReorderFlexMinxi, TickerP
|
|
]);
|
|
]);
|
|
} else if (childIndex == dragPhantomIndex) {
|
|
} else if (childIndex == dragPhantomIndex) {
|
|
return _buildDraggingContainer(
|
|
return _buildDraggingContainer(
|
|
- children: shiftedIndex >= childIndex ? [disappearSpace, dragTarget] : [dragTarget, disappearSpace]);
|
|
|
|
|
|
+ children: shiftedIndex >= childIndex
|
|
|
|
+ ? [disappearSpace, dragTarget]
|
|
|
|
+ : [dragTarget, disappearSpace]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -282,22 +284,25 @@ class ReorderFlexState extends State<ReorderFlex> with ReorderFlexMinxi, TickerP
|
|
Widget child,
|
|
Widget child,
|
|
int dragTargetIndex,
|
|
int dragTargetIndex,
|
|
) {
|
|
) {
|
|
- final ReoderFlexItem reorderFlexItem = widget.dataSource.items[dragTargetIndex];
|
|
|
|
|
|
+ final ReoderFlexItem reorderFlexItem =
|
|
|
|
+ widget.dataSource.items[dragTargetIndex];
|
|
return ReorderDragTarget<FlexDragTargetData>(
|
|
return ReorderDragTarget<FlexDragTargetData>(
|
|
dragTargetData: FlexDragTargetData(
|
|
dragTargetData: FlexDragTargetData(
|
|
draggingIndex: dragTargetIndex,
|
|
draggingIndex: dragTargetIndex,
|
|
|
|
+ reorderFlexId: widget.reorderFlexId,
|
|
reorderFlexItem: reorderFlexItem,
|
|
reorderFlexItem: reorderFlexItem,
|
|
state: dragState,
|
|
state: dragState,
|
|
- draggingReorderFlex: widget,
|
|
|
|
dragTargetId: reorderFlexItem.id,
|
|
dragTargetId: reorderFlexItem.id,
|
|
),
|
|
),
|
|
onDragStarted: (draggingWidget, draggingIndex, size) {
|
|
onDragStarted: (draggingWidget, draggingIndex, size) {
|
|
- Log.debug("[DragTarget] Column${widget.dataSource.identifier} start dragging");
|
|
|
|
|
|
+ Log.debug(
|
|
|
|
+ "[DragTarget] Column${widget.dataSource.identifier} start dragging");
|
|
_startDragging(draggingWidget, draggingIndex, size);
|
|
_startDragging(draggingWidget, draggingIndex, size);
|
|
widget.onDragStarted?.call(draggingIndex);
|
|
widget.onDragStarted?.call(draggingIndex);
|
|
},
|
|
},
|
|
onDragEnded: (dragTargetData) {
|
|
onDragEnded: (dragTargetData) {
|
|
- Log.debug("[DragTarget]: Column${widget.dataSource.identifier} end dragging");
|
|
|
|
|
|
+ Log.debug(
|
|
|
|
+ "[DragTarget]: Column${widget.dataSource.identifier} end dragging");
|
|
|
|
|
|
setState(() {
|
|
setState(() {
|
|
_onReordered(
|
|
_onReordered(
|
|
@@ -323,8 +328,7 @@ class ReorderFlexState extends State<ReorderFlex> with ReorderFlexMinxi, TickerP
|
|
)) {
|
|
)) {
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
- final dragIndex = dragTargetData.draggingIndex;
|
|
|
|
- return handleOnWillAccept(builderContext, dragIndex, dragTargetIndex);
|
|
|
|
|
|
+ return handleOnWillAccept(builderContext, dragTargetIndex);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
onAccept: (dragTargetData) {
|
|
onAccept: (dragTargetData) {
|
|
@@ -386,14 +390,17 @@ class ReorderFlexState extends State<ReorderFlex> with ReorderFlexMinxi, TickerP
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- bool handleOnWillAccept(BuildContext context, int? dragIndex, int dragTargetIndex) {
|
|
|
|
|
|
+ bool handleOnWillAccept(BuildContext context, int dragTargetIndex) {
|
|
|
|
+ final dragIndex = dragState.dragStartIndex;
|
|
|
|
+
|
|
/// The [willAccept] will be true if the dargTarget is the widget that gets
|
|
/// The [willAccept] will be true if the dargTarget is the widget that gets
|
|
/// dragged and it is dragged on top of the other dragTargets.
|
|
/// dragged and it is dragged on top of the other dragTargets.
|
|
///
|
|
///
|
|
Log.debug(
|
|
Log.debug(
|
|
'[$ReorderDragTarget] ${widget.dataSource.identifier} on will accept, dragIndex:$dragIndex, dragTargetIndex:$dragTargetIndex, count: ${widget.dataSource.items.length}');
|
|
'[$ReorderDragTarget] ${widget.dataSource.identifier} on will accept, dragIndex:$dragIndex, dragTargetIndex:$dragTargetIndex, count: ${widget.dataSource.items.length}');
|
|
|
|
|
|
- bool willAccept = dragState.dragStartIndex == dragIndex && dragIndex != dragTargetIndex;
|
|
|
|
|
|
+ bool willAccept =
|
|
|
|
+ dragState.dragStartIndex == dragIndex && dragIndex != dragTargetIndex;
|
|
setState(() {
|
|
setState(() {
|
|
if (willAccept) {
|
|
if (willAccept) {
|
|
int shiftedIndex = dragState.calculateShiftedIndex(dragTargetIndex);
|
|
int shiftedIndex = dragState.calculateShiftedIndex(dragTargetIndex);
|
|
@@ -420,7 +427,8 @@ class ReorderFlexState extends State<ReorderFlex> with ReorderFlexMinxi, TickerP
|
|
}
|
|
}
|
|
|
|
|
|
Widget _wrapScrollView({required Widget child}) {
|
|
Widget _wrapScrollView({required Widget child}) {
|
|
- if (widget.scrollController != null && PrimaryScrollController.of(context) == null) {
|
|
|
|
|
|
+ if (widget.scrollController != null &&
|
|
|
|
+ PrimaryScrollController.of(context) == null) {
|
|
return child;
|
|
return child;
|
|
} else {
|
|
} else {
|
|
return SingleChildScrollView(
|
|
return SingleChildScrollView(
|
|
@@ -474,12 +482,14 @@ class ReorderFlexState extends State<ReorderFlex> with ReorderFlexMinxi, TickerP
|
|
void _scrollTo(BuildContext context) {
|
|
void _scrollTo(BuildContext context) {
|
|
if (_scrolling) return;
|
|
if (_scrolling) return;
|
|
final RenderObject contextObject = context.findRenderObject()!;
|
|
final RenderObject contextObject = context.findRenderObject()!;
|
|
- final RenderAbstractViewport viewport = RenderAbstractViewport.of(contextObject)!;
|
|
|
|
|
|
+ final RenderAbstractViewport viewport =
|
|
|
|
+ RenderAbstractViewport.of(contextObject)!;
|
|
// If and only if the current scroll offset falls in-between the offsets
|
|
// 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
|
|
// necessary to reveal the selected context at the top or bottom of the
|
|
// screen, then it is already on-screen.
|
|
// screen, then it is already on-screen.
|
|
- final double margin =
|
|
|
|
- widget.direction == Axis.horizontal ? dragState.dropAreaSize.width : dragState.dropAreaSize.height;
|
|
|
|
|
|
+ final double margin = widget.direction == Axis.horizontal
|
|
|
|
+ ? dragState.dropAreaSize.width
|
|
|
|
+ : dragState.dropAreaSize.height;
|
|
if (_scrollController.hasClients) {
|
|
if (_scrollController.hasClients) {
|
|
final double scrollOffset = _scrollController.offset;
|
|
final double scrollOffset = _scrollController.offset;
|
|
final double topOffset = max(
|
|
final double topOffset = max(
|
|
@@ -490,7 +500,8 @@ class ReorderFlexState extends State<ReorderFlex> with ReorderFlexMinxi, TickerP
|
|
_scrollController.position.maxScrollExtent,
|
|
_scrollController.position.maxScrollExtent,
|
|
viewport.getOffsetToReveal(contextObject, 1.0).offset + margin,
|
|
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 the context is off screen, then we request a scroll to make it visible.
|
|
if (!onScreen) {
|
|
if (!onScreen) {
|