fix: fix some bugs

This commit is contained in:
appflowy 2022-08-04 23:30:27 +08:00
parent e8dad2ef03
commit 146cc5c5e9
6 changed files with 87 additions and 130 deletions

View File

@ -122,16 +122,14 @@ class BoardContent extends StatefulWidget {
} }
class _BoardContentState extends State<BoardContent> { class _BoardContentState extends State<BoardContent> {
final GlobalKey _columnContainerOverlayKey = final GlobalKey _columnContainerOverlayKey = GlobalKey(debugLabel: '$BoardContent overlay key');
GlobalKey(debugLabel: '$BoardContent overlay key');
late BoardOverlayEntry _overlayEntry; late BoardOverlayEntry _overlayEntry;
@override @override
void initState() { void initState() {
_overlayEntry = BoardOverlayEntry( _overlayEntry = BoardOverlayEntry(
builder: (BuildContext context) { builder: (BuildContext context) {
List<Widget> children = List<Widget> children = widget.dataController.columnDatas.map((columnData) {
widget.dataController.columnDatas.map((columnData) {
return _buildColumn( return _buildColumn(
columnData.id, columnData.id,
widget.dataController.columnIds, widget.dataController.columnIds,

View File

@ -1,3 +1,5 @@
import 'dart:collection';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../utils/log.dart'; import '../../utils/log.dart';
@ -8,22 +10,26 @@ abstract class ColumnItem extends ReoderFlexItem {
@override @override
String toString() { String toString() {
return id; if (isPhantom) {
return 'phantom:$id';
} else {
return id;
}
} }
} }
class BoardColumnData extends ReoderFlexItem with EquatableMixin { class BoardColumnData extends ReoderFlexItem with EquatableMixin {
@override @override
final String id; final String id;
final List<ColumnItem> items; final List<ColumnItem> _items;
BoardColumnData({ BoardColumnData({
required this.id, required this.id,
required this.items, required List<ColumnItem> items,
}); }) : _items = items;
@override @override
List<Object?> get props => [id, ...items]; List<Object?> get props => [id, ..._items];
@override @override
String toString() { String toString() {
@ -31,8 +37,7 @@ class BoardColumnData extends ReoderFlexItem with EquatableMixin {
} }
} }
class BoardColumnDataController extends ChangeNotifier class BoardColumnDataController extends ChangeNotifier with EquatableMixin, ReoderFlextDataSource {
with EquatableMixin, ReoderFlextDataSource {
final BoardColumnData columnData; final BoardColumnData columnData;
BoardColumnDataController({ BoardColumnDataController({
@ -42,10 +47,12 @@ class BoardColumnDataController extends ChangeNotifier
@override @override
List<Object?> get props => columnData.props; List<Object?> get props => columnData.props;
ColumnItem removeAt(int index) { ColumnItem removeAt(int index, {bool notify = true}) {
Log.debug('[$BoardColumnDataController] $columnData remove item at $index'); Log.debug('[$BoardColumnDataController] $columnData remove item at $index');
final item = columnData.items.removeAt(index); final item = columnData._items.removeAt(index);
notifyListeners(); if (notify) {
notifyListeners();
}
return item; return item;
} }
@ -53,31 +60,29 @@ class BoardColumnDataController extends ChangeNotifier
if (fromIndex == toIndex) { if (fromIndex == toIndex) {
return; return;
} }
Log.debug( Log.debug('[$BoardColumnDataController] $columnData move item from $fromIndex to $toIndex');
'[$BoardColumnDataController] $columnData move item from $fromIndex to $toIndex'); final item = columnData._items.removeAt(fromIndex);
final item = columnData.items.removeAt(fromIndex); columnData._items.insert(toIndex, item);
columnData.items.insert(toIndex, item);
notifyListeners(); notifyListeners();
} }
void insert(int index, ColumnItem item, {bool notify = true}) { void insert(int index, ColumnItem item, {bool notify = true}) {
Log.debug('[$BoardColumnDataController] $columnData insert item at $index'); Log.debug('[$BoardColumnDataController] $columnData insert $item at $index');
columnData.items.insert(index, item); columnData._items.insert(index, item);
if (notify) { if (notify) {
notifyListeners(); notifyListeners();
} }
} }
void replace(int index, ColumnItem item) { void replace(int index, ColumnItem item) {
Log.debug( final removedItem = columnData._items.removeAt(index);
'[$BoardColumnDataController] $columnData replace item at $index'); columnData._items.insert(index, item);
columnData.items.removeAt(index); Log.debug('[$BoardColumnDataController] $columnData replace $removedItem with $item at $index');
columnData.items.insert(index, item);
notifyListeners(); notifyListeners();
} }
@override @override
List<ColumnItem> get items => columnData.items; List<ColumnItem> get items => UnmodifiableListView(columnData._items);
@override @override
String get identifier => columnData.id; String get identifier => columnData.id;

View File

@ -22,14 +22,14 @@ class FlexDragTargetData extends DragTargetData {
final String dragTargetId; final String dragTargetId;
ReoderFlexItem get reorderFlexItem => final ReoderFlexItem reorderFlexItem;
draggingReorderFlex.itemAtIndex(draggingIndex);
String get reorderFlexId => draggingReorderFlex.reorderFlexId; String get reorderFlexId => draggingReorderFlex.reorderFlexId;
FlexDragTargetData({ FlexDragTargetData({
required this.dragTargetId, required this.dragTargetId,
required this.draggingIndex, required this.draggingIndex,
required this.reorderFlexItem,
required this.state, required this.state,
required this.draggingReorderFlex, required this.draggingReorderFlex,
}); });
@ -85,12 +85,10 @@ class DraggingState {
if (_draggingFeedbackSize == null) { if (_draggingFeedbackSize == null) {
return Size.zero; return Size.zero;
} }
return _draggingFeedbackSize! + return _draggingFeedbackSize! + const Offset(_dropAreaMargin, _dropAreaMargin);
const Offset(_dropAreaMargin, _dropAreaMargin);
} }
void startDragging(Widget draggingWidget, int draggingWidgetIndex, void startDragging(Widget draggingWidget, int draggingWidgetIndex, Size? draggingWidgetSize) {
Size? draggingWidgetSize) {
/// ///
assert(draggingWidgetIndex >= 0); assert(draggingWidgetIndex >= 0);

View File

@ -25,8 +25,7 @@ abstract class ReorderFlexDragTargetInterceptor {
abstract class OverlapReorderFlexDragTargetDelegate {} abstract class OverlapReorderFlexDragTargetDelegate {}
class OverlapReorderFlexDragTargetInteceptor class OverlapReorderFlexDragTargetInteceptor extends ReorderFlexDragTargetInterceptor {
extends ReorderFlexDragTargetInterceptor {
final String reorderFlexId; final String reorderFlexId;
final List<String> acceptedReorderFlexId; final List<String> acceptedReorderFlexId;
final OverlapReorderFlexDragTargetDelegate delegate; final OverlapReorderFlexDragTargetDelegate delegate;
@ -71,8 +70,7 @@ abstract class CrossReorderFlexDragTargetDelegate {
); );
} }
class CrossReorderFlexDragTargetInterceptor class CrossReorderFlexDragTargetInterceptor extends ReorderFlexDragTargetInterceptor {
extends ReorderFlexDragTargetInterceptor {
final String reorderFlexId; final String reorderFlexId;
final List<String> acceptedReorderFlexIds; final List<String> acceptedReorderFlexIds;
final CrossReorderFlexDragTargetDelegate delegate; final CrossReorderFlexDragTargetDelegate delegate;
@ -104,14 +102,12 @@ class CrossReorderFlexDragTargetInterceptor
@override @override
void onAccept(FlexDragTargetData dragTargetData) { void onAccept(FlexDragTargetData dragTargetData) {
Log.trace( Log.trace('[$CrossReorderFlexDragTargetInterceptor] Column$reorderFlexId on onAccept');
'[$CrossReorderFlexDragTargetInterceptor] Column$reorderFlexId on onAccept');
} }
@override @override
void onLeave(FlexDragTargetData dragTargetData) { void onLeave(FlexDragTargetData dragTargetData) {
Log.trace( Log.trace('[$CrossReorderFlexDragTargetInterceptor] Column$reorderFlexId on leave');
'[$CrossReorderFlexDragTargetInterceptor] Column$reorderFlexId on leave');
} }
@override @override
@ -134,7 +130,7 @@ class CrossReorderFlexDragTargetInterceptor
dragTargetIndex, dragTargetIndex,
); );
reorderFlexState.onWillAccept( reorderFlexState.handleOnWillAccept(
context, context,
dragTargetData.draggingIndex, dragTargetData.draggingIndex,
dragTargetIndex, dragTargetIndex,

View File

@ -13,8 +13,7 @@ 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( typedef OnReveivePassedInPhantom = void Function(FlexDragTargetData dragTargetData, int phantomIndex);
FlexDragTargetData dragTargetData, int phantomIndex);
abstract class ReoderFlextDataSource { abstract class ReoderFlextDataSource {
String get identifier; String get identifier;
@ -78,8 +77,7 @@ class ReorderFlex extends StatefulWidget with DraggingReorderFlex {
} }
} }
class ReorderFlexState extends State<ReorderFlex> class ReorderFlexState extends State<ReorderFlex> with ReorderFlexMinxi, TickerProviderStateMixin<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;
@ -115,9 +113,7 @@ class ReorderFlexState extends State<ReorderFlex>
_attachedScrollPosition = null; _attachedScrollPosition = null;
} }
_scrollController = widget.scrollController ?? _scrollController = widget.scrollController ?? PrimaryScrollController.of(context) ?? ScrollController();
PrimaryScrollController.of(context) ??
ScrollController();
if (_scrollController.hasClients) { if (_scrollController.hasClients) {
_attachedScrollPosition = Scrollable.of(context)?.position; _attachedScrollPosition = Scrollable.of(context)?.position;
@ -239,9 +235,7 @@ class ReorderFlexState extends State<ReorderFlex>
]); ]);
} else if (childIndex == dragPhantomIndex) { } else if (childIndex == dragPhantomIndex) {
return _buildDraggingContainer( return _buildDraggingContainer(
children: shiftedIndex <= childIndex children: shiftedIndex <= childIndex ? [dragTarget, disappearSpace] : [disappearSpace, dragTarget]);
? [dragTarget, disappearSpace]
: [disappearSpace, dragTarget]);
} }
} }
@ -262,9 +256,7 @@ class ReorderFlexState extends State<ReorderFlex>
]); ]);
} else if (childIndex == dragPhantomIndex) { } else if (childIndex == dragPhantomIndex) {
return _buildDraggingContainer( return _buildDraggingContainer(
children: shiftedIndex >= childIndex children: shiftedIndex >= childIndex ? [disappearSpace, dragTarget] : [dragTarget, disappearSpace]);
? [disappearSpace, dragTarget]
: [dragTarget, disappearSpace]);
} }
} }
@ -290,21 +282,22 @@ class ReorderFlexState extends State<ReorderFlex>
Widget child, Widget child,
int dragTargetIndex, int dragTargetIndex,
) { ) {
final ReoderFlexItem item = 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,
reorderFlexItem: reorderFlexItem,
state: dragState, state: dragState,
draggingReorderFlex: widget, draggingReorderFlex: widget,
dragTargetId: item.id, dragTargetId: reorderFlexItem.id,
), ),
onDragStarted: (draggingWidget, draggingIndex, size) { onDragStarted: (draggingWidget, draggingIndex, size) {
Log.debug("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("Column${widget.dataSource.identifier} end dragging"); Log.debug("[DragTarget]: Column${widget.dataSource.identifier} end dragging");
setState(() { setState(() {
_onReordered( _onReordered(
@ -317,22 +310,21 @@ class ReorderFlexState extends State<ReorderFlex>
}, },
onWillAccept: (FlexDragTargetData dragTargetData) { onWillAccept: (FlexDragTargetData dragTargetData) {
assert(widget.dataSource.items.length > dragTargetIndex); assert(widget.dataSource.items.length > dragTargetIndex);
Log.debug(
'[$ReorderDragTarget] ${widget.dataSource.identifier} on will accept, count: ${widget.dataSource.items.length}');
if (_interceptDragTarget( if (_interceptDragTarget(
dragTargetData, dragTargetData,
(interceptor) => interceptor.onWillAccept( (interceptor) => interceptor.onWillAccept(
context: builderContext, context: builderContext,
reorderFlexState: this, reorderFlexState: this,
dragTargetData: dragTargetData, dragTargetData: dragTargetData,
dragTargetId: item.id, dragTargetId: reorderFlexItem.id,
dragTargetIndex: dragTargetIndex, dragTargetIndex: dragTargetIndex,
), ),
)) { )) {
return true; return true;
} else { } else {
final dragIndex = dragTargetData.draggingIndex; final dragIndex = dragTargetData.draggingIndex;
return onWillAccept(builderContext, dragIndex, dragTargetIndex); return handleOnWillAccept(builderContext, dragIndex, dragTargetIndex);
} }
}, },
onAccept: (dragTargetData) { onAccept: (dragTargetData) {
@ -394,11 +386,14 @@ class ReorderFlexState extends State<ReorderFlex>
}); });
} }
bool onWillAccept(BuildContext context, int? dragIndex, int childIndex) { bool handleOnWillAccept(BuildContext context, int? dragIndex, int childIndex) {
/// 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.
bool willAccept = ///
dragState.dragStartIndex == dragIndex && dragIndex != childIndex; Log.trace(
'[$ReorderDragTarget] ${widget.dataSource.identifier} on will accept, count: ${widget.dataSource.items.length}');
bool willAccept = dragState.dragStartIndex == dragIndex && dragIndex != childIndex;
setState(() { setState(() {
if (willAccept) { if (willAccept) {
int shiftedIndex = dragState.calculateShiftedIndex(childIndex); int shiftedIndex = dragState.calculateShiftedIndex(childIndex);
@ -425,8 +420,7 @@ class ReorderFlexState extends State<ReorderFlex>
} }
Widget _wrapScrollView({required Widget child}) { Widget _wrapScrollView({required Widget child}) {
if (widget.scrollController != null && if (widget.scrollController != null && PrimaryScrollController.of(context) == null) {
PrimaryScrollController.of(context) == null) {
return child; return child;
} else { } else {
return SingleChildScrollView( return SingleChildScrollView(
@ -480,14 +474,12 @@ class ReorderFlexState extends State<ReorderFlex>
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 = final RenderAbstractViewport viewport = RenderAbstractViewport.of(contextObject)!;
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 final double margin =
? dragState.dropAreaSize.width widget.direction == Axis.horizontal ? dragState.dropAreaSize.width : dragState.dropAreaSize.height;
: 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(
@ -498,8 +490,7 @@ class ReorderFlexState extends State<ReorderFlex>
_scrollController.position.maxScrollExtent, _scrollController.position.maxScrollExtent,
viewport.getOffsetToReveal(contextObject, 1.0).offset + margin, viewport.getOffsetToReveal(contextObject, 1.0).offset + margin,
); );
final bool onScreen = final bool onScreen = scrollOffset <= topOffset && scrollOffset >= bottomOffset;
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) {

View File

@ -14,8 +14,7 @@ mixin ColumnDataPhantomMixim {
BoardColumnDataController? get; BoardColumnDataController? get;
} }
class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate with CrossReorderFlexDragTargetDelegate {
with CrossReorderFlexDragTargetDelegate {
final BoardPhantomControllerDelegate delegate; final BoardPhantomControllerDelegate delegate;
PhantomRecord? phantomRecord; PhantomRecord? phantomRecord;
@ -64,22 +63,12 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
if (columnsState.isDragging(phantomRecord!.fromColumnId) == false) { if (columnsState.isDragging(phantomRecord!.fromColumnId) == false) {
return; return;
} }
final item = delegate.controller(phantomRecord!.fromColumnId)?.removeAt(phantomRecord!.fromColumnIndex);
Log.debug("[$BoardPhantomController] move ${phantomRecord.toString()}");
final item = delegate
.controller(phantomRecord!.fromColumnId)
?.removeAt(phantomRecord!.fromColumnIndex);
assert(item != null); assert(item != null);
assert(delegate assert(delegate.controller(phantomRecord!.toColumnId)?.items[phantomRecord!.toColumnIndex] is PhantomColumnItem);
.controller(phantomRecord!.toColumnId) delegate.controller(phantomRecord!.toColumnId)?.replace(phantomRecord!.toColumnIndex, item!);
?.items[phantomRecord!.toColumnIndex] is PhantomColumnItem);
delegate
.controller(phantomRecord!.toColumnId)
?.replace(phantomRecord!.toColumnIndex, item!);
Log.debug("[$BoardPhantomController] did move ${phantomRecord.toString()}");
phantomRecord = null; phantomRecord = null;
} }
@ -88,28 +77,22 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
FlexDragTargetData dragTargetData, FlexDragTargetData dragTargetData,
int phantomIndex, int phantomIndex,
) { ) {
final items = delegate.controller(toColumnId)?.items; final columnDataController = delegate.controller(toColumnId);
if (items == null) { final index = columnDataController?.items.indexWhere((item) => item.isPhantom);
return; if (index == null) return;
}
final index = items.indexWhere((item) => item.isPhantom);
assert(index != -1); assert(index != -1);
if (index != -1) { if (index != -1) {
if (index != phantomIndex) { if (index != phantomIndex) {
Log.debug( // Log.debug('[$BoardPhantomController] update $toColumnId:$index to $toColumnId:$phantomIndex');
'[$BoardPhantomController] move phantom $toColumnId:$index to $toColumnId:$phantomIndex'); final item = columnDataController!.removeAt(index, notify: false);
final item = items.removeAt(index); columnDataController.insert(phantomIndex, item, notify: false);
items.insert(phantomIndex, item);
} }
} }
} }
void _removePhantom(String columnId) { void _removePhantom(String columnId) {
final index = delegate final index = delegate.controller(columnId)?.items.indexWhere((item) => item.isPhantom);
.controller(columnId)
?.items
.indexWhere((item) => item.isPhantom);
if (index == null) return; if (index == null) return;
@ -139,15 +122,11 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
dragTargetData: dragTargetData, dragTargetData: dragTargetData,
); );
columnsState.addColumnListener(toColumnId, phantomContext); columnsState.addColumnListener(toColumnId, phantomContext);
Log.debug('$phantomContext');
Log.debug( delegate.controller(toColumnId)?.insert(phantomIndex, PhantomColumnItem(phantomContext));
'[$BoardPhantomController] Column$toColumnId insert phantom at $phantomIndex');
delegate
.controller(toColumnId)
?.insert(phantomIndex, PhantomColumnItem(phantomContext));
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
Future.delayed(const Duration(microseconds: 100), () { Future.delayed(const Duration(milliseconds: 00), () {
columnsState.notifyDidInsertPhantom(toColumnId); columnsState.notifyDidInsertPhantom(toColumnId);
}); });
}); });
@ -158,9 +137,8 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
FlexDragTargetData dragTargetData, FlexDragTargetData dragTargetData,
int index, int index,
) { ) {
Log.debug( // Log.debug('[$BoardPhantomController] move Column${dragTargetData.reorderFlexId}:${dragTargetData.draggingIndex} '
'[$BoardPhantomController] move Column${dragTargetData.reorderFlexId}:${dragTargetData.draggingIndex} ' // 'to Column$columnId:$index');
'to Column$columnId:$index');
phantomRecord = PhantomRecord( phantomRecord = PhantomRecord(
toColumnId: columnId, toColumnId: columnId,
@ -169,11 +147,11 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
fromColumnId: dragTargetData.reorderFlexId, fromColumnId: dragTargetData.reorderFlexId,
fromColumnIndex: dragTargetData.draggingIndex, fromColumnIndex: dragTargetData.draggingIndex,
); );
Log.debug('[$BoardPhantomController] will move: $phantomRecord');
} }
@override @override
bool acceptNewDragTargetData( bool acceptNewDragTargetData(String reorderFlexId, FlexDragTargetData dragTargetData, int index) {
String reorderFlexId, FlexDragTargetData dragTargetData, int index) {
if (phantomRecord == null) { if (phantomRecord == null) {
_updatePhantomRecord(reorderFlexId, dragTargetData, index); _updatePhantomRecord(reorderFlexId, dragTargetData, index);
_insertPhantom(reorderFlexId, dragTargetData, index); _insertPhantom(reorderFlexId, dragTargetData, index);
@ -181,8 +159,6 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
} }
final isNewDragTarget = phantomRecord!.toColumnId != reorderFlexId; final isNewDragTarget = phantomRecord!.toColumnId != reorderFlexId;
Log.debug(
'[$BoardPhantomController] Set inserted column id: $reorderFlexId, is new target: $isNewDragTarget');
if (isNewDragTarget) { if (isNewDragTarget) {
/// Remove the phantom in the previous column. /// Remove the phantom in the previous column.
_removePhantom(phantomRecord!.toColumnId); _removePhantom(phantomRecord!.toColumnId);
@ -196,8 +172,7 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
} }
@override @override
void updateDragTargetData( void updateDragTargetData(String reorderFlexId, FlexDragTargetData dragTargetData, int index) {
String reorderFlexId, FlexDragTargetData dragTargetData, int index) {
phantomRecord?.updateInsertedIndex(index); phantomRecord?.updateInsertedIndex(index);
assert(phantomRecord != null); assert(phantomRecord != null);
@ -228,34 +203,29 @@ class PhantomRecord {
if (fromColumnIndex == index) { if (fromColumnIndex == index) {
return; return;
} }
Log.info( Log.debug('[$PhantomRecord] Update Column$fromColumnId remove position to $index');
'[$PhantomRecord] Update Column$fromColumnId remove position to $index');
fromColumnIndex = index; fromColumnIndex = index;
} }
void updateInsertedIndex(int index) { void updateInsertedIndex(int index) {
if (toColumnIndex == index) { if (toColumnIndex == index) {
Log.info(
'[$PhantomRecord] Column$toColumnId toColumnIndex: $toColumnIndex, index: $index');
return; return;
} }
Log.info( Log.debug('[$PhantomRecord] Column$toColumnId update position $toColumnIndex -> $index');
'[$PhantomRecord] Update Column$toColumnId phantom position to $index');
toColumnIndex = index; toColumnIndex = index;
} }
@override @override
String toString() { String toString() {
return '$fromColumnId:$fromColumnIndex to $toColumnId:$toColumnIndex'; return 'Column$fromColumnId:$fromColumnIndex to Column$toColumnId:$toColumnIndex';
} }
} }
class PhantomColumnItem extends ColumnItem { class PhantomColumnItem extends ColumnItem {
final PassthroughPhantomContext phantomContext; final PassthroughPhantomContext phantomContext;
PhantomColumnItem(PassthroughPhantomContext insertedPhantom) PhantomColumnItem(PassthroughPhantomContext insertedPhantom) : phantomContext = insertedPhantom;
: phantomContext = insertedPhantom;
@override @override
bool get isPhantom => true; bool get isPhantom => true;
@ -265,9 +235,8 @@ class PhantomColumnItem extends ColumnItem {
Size? get feedbackSize => phantomContext.feedbackSize; Size? get feedbackSize => phantomContext.feedbackSize;
Widget get draggingWidget => phantomContext.draggingWidget == null Widget get draggingWidget =>
? const SizedBox() phantomContext.draggingWidget == null ? const SizedBox() : phantomContext.draggingWidget!;
: phantomContext.draggingWidget!;
} }
class PassthroughPhantomContext extends FakeDragTargetEventTrigger class PassthroughPhantomContext extends FakeDragTargetEventTrigger