Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: reorder bugs
appflowyc25237c7671a
diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board.dartindex c3bbe9824f..1e52e7a3aa 100644--- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board.dart+++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board.dart@@ -129,24 +129,16 @@ class _BoardContentState extends State<BoardContent> {void initState() {_overlayEntry = BoardOverlayEntry(builder: (BuildContext context) {- List<Widget> children = widget.dataController.columnDatas.map((columnData) {- return _buildColumn(- columnData.id,- widget.dataController.columnIds,- widget.dataController.columnController(columnData.id),- );- }).toList();-final interceptor = OverlapReorderFlexDragTargetInteceptor(reorderFlexId: widget.dataController.identifier,acceptedReorderFlexId: widget.dataController.columnIds,delegate: widget.delegate,);- Widget reorderFlex = ReorderFlex(+ final reorderFlex = ReorderFlex(key: widget.key,- scrollController: widget.scrollController,config: widget.config,+ scrollController: widget.scrollController,onDragStarted: widget.onDragStarted,onReorder: widget.onReorder,onDragEnded: widget.onDragEnded,@@ -154,7 +146,7 @@ class _BoardContentState extends State<BoardContent> {direction: Axis.horizontal,spacing: widget.spacing,interceptor: interceptor,- children: children,+ children: _buildColumns(),);return Stack(@@ -178,33 +170,37 @@ class _BoardContentState extends State<BoardContent> {);}- Widget _buildColumn(- String columnId,- List<String> acceptColumns,- BoardColumnDataController dataController,- ) {- return ChangeNotifierProvider.value(- key: ValueKey(columnId),- value: dataController,- child: Consumer<BoardColumnDataController>(- builder: (context, value, child) {- return ConstrainedBox(- constraints: widget.columnConstraints,- child: BoardColumnWidget(- headerBuilder: widget.headerBuilder,- footBuilder: widget.footBuilder,- cardBuilder: widget.cardBuilder,- acceptedColumns: acceptColumns,- dataController: dataController,- scrollController: ScrollController(),- onReorder: (_, int fromIndex, int toIndex) {- dataController.move(fromIndex, toIndex);- },- phantomController: widget.phantomController,- ),- );- },- ),- );+ List<Widget> _buildColumns() {+ final acceptColumns = widget.dataController.columnIds;++ final List<Widget> children = widget.dataController.columnDatas.map((columnData) {+ final dataController = widget.dataController.columnController(columnData.id);++ return ChangeNotifierProvider.value(+ key: ValueKey(columnData.id),+ value: dataController,+ child: Consumer<BoardColumnDataController>(+ builder: (context, value, child) {+ return ConstrainedBox(+ constraints: widget.columnConstraints,+ child: BoardColumnWidget(+ headerBuilder: widget.headerBuilder,+ footBuilder: widget.footBuilder,+ cardBuilder: widget.cardBuilder,+ acceptedColumns: acceptColumns,+ dataController: dataController,+ scrollController: ScrollController(),+ phantomController: widget.phantomController,+ onReorder: (_, int fromIndex, int toIndex) {+ dataController.move(fromIndex, toIndex);+ },+ ),+ );+ },+ ),+ );+ }).toList();++ return children;}}diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_state.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_state.dartindex 1de8b843a0..a5496bc9d8 100644--- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_state.dart+++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_state.dart@@ -15,7 +15,7 @@ class FlexDragTargetData extends DragTargetData {Widget? get draggingWidget => state.draggingWidget;- Size? get draggingFeedbackSize => state.feedbackSize;+ Size? get feedbackSize => state.feedbackSize;/// Indicate the dragTarget come from which [ReorderFlex].final DraggingReorderFlex draggingReorderFlex;diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_target_inteceptor.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_target_inteceptor.dartindex b1f933f577..0495eeae14 100644--- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_target_inteceptor.dart+++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_target_inteceptor.dart@@ -66,7 +66,7 @@ abstract class CrossReorderFlexDragTargetDelegate {void updateDragTargetData(String reorderFlexId,FlexDragTargetData dragTargetData,- int index,+ int dragTargetIndex,);}diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/reorder_flex.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/reorder_flex.dartindex 242bd77785..a7c4940f6d 100644--- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/reorder_flex.dart+++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/reorder_flex.dart@@ -386,20 +386,20 @@ class ReorderFlexState extends State<ReorderFlex> with ReorderFlexMinxi, TickerP});}- bool handleOnWillAccept(BuildContext context, int? dragIndex, int childIndex) {+ bool handleOnWillAccept(BuildContext context, int? dragIndex, int dragTargetIndex) {/// The [willAccept] will be true if the dargTarget is the widget that gets/// dragged and it is dragged on top of the other dragTargets.///- Log.trace(- '[$ReorderDragTarget] ${widget.dataSource.identifier} on will accept, count: ${widget.dataSource.items.length}');+ Log.debug(+ '[$ReorderDragTarget] ${widget.dataSource.identifier} on will accept, dragIndex:$dragIndex, dragTargetIndex:$dragTargetIndex, count: ${widget.dataSource.items.length}');- bool willAccept = dragState.dragStartIndex == dragIndex && dragIndex != childIndex;+ bool willAccept = dragState.dragStartIndex == dragIndex && dragIndex != dragTargetIndex;setState(() {if (willAccept) {- int shiftedIndex = dragState.calculateShiftedIndex(childIndex);+ int shiftedIndex = dragState.calculateShiftedIndex(dragTargetIndex);dragState.updateNextIndex(shiftedIndex);} else {- dragState.updateNextIndex(childIndex);+ dragState.updateNextIndex(dragTargetIndex);}_requestAnimationToNextIndex(isAcceptingNewTarget: true);diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/phantom/phantom_controller.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/phantom/phantom_controller.dartindex b7074ed01a..6e2a5195f3 100644--- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/phantom/phantom_controller.dart+++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/phantom/phantom_controller.dart@@ -1,4 +1,5 @@import 'package:flutter/material.dart';+import 'package:flutter/scheduler.dart';import '../../../flowy_board.dart';import '../../utils/log.dart';import '../flex/drag_state.dart';@@ -126,7 +127,7 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate with Cdelegate.controller(toColumnId)?.insert(phantomIndex, PhantomColumnItem(phantomContext));WidgetsBinding.instance.addPostFrameCallback((_) {- Future.delayed(const Duration(milliseconds: 00), () {+ Future.delayed(const Duration(milliseconds: 100), () {columnsState.notifyDidInsertPhantom(toColumnId);});});@@ -172,13 +173,13 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate with C}@override- void updateDragTargetData(String reorderFlexId, FlexDragTargetData dragTargetData, int index) {- phantomRecord?.updateInsertedIndex(index);+ void updateDragTargetData(String reorderFlexId, FlexDragTargetData dragTargetData, int dragTargetIndex) {+ phantomRecord?.updateInsertedIndex(dragTargetIndex);assert(phantomRecord != null);if (phantomRecord!.toColumnId == reorderFlexId) {/// Update the existing phantom index- _updatePhantom(phantomRecord!.toColumnId, dragTargetData, index);+ _updatePhantom(phantomRecord!.toColumnId, dragTargetData, dragTargetIndex);}}}