chore: update import path

This commit is contained in:
appflowy 2022-08-07 10:46:31 +08:00
parent c035c9cf93
commit 621c9615a1
11 changed files with 116 additions and 61 deletions

View File

@ -9,7 +9,18 @@ class MultiBoardListExample extends StatefulWidget {
}
class _MultiBoardListExampleState extends State<MultiBoardListExample> {
final BoardDataController boardDataController = BoardDataController();
final BoardDataController boardDataController = BoardDataController(
onMoveColumn: (fromIndex, toIndex) {
debugPrint('Move column from $fromIndex to $toIndex');
},
onMoveColumnItem: (columnId, fromIndex, toIndex) {
debugPrint('Column:$columnId move item from $fromIndex to $toIndex');
},
onMoveColumnItemToColumn: (fromColumnId, fromIndex, toColumnId, toIndex) {
debugPrint(
'Column:$fromColumnId move item at $fromIndex to column:$toColumnId $toIndex');
},
);
@override
void initState() {
@ -34,9 +45,9 @@ class _MultiBoardListExampleState extends State<MultiBoardListExample> {
TextItem("D"),
]);
boardDataController.setColumnData(column1);
boardDataController.setColumnData(column2);
boardDataController.setColumnData(column3);
boardDataController.addColumn(column1);
boardDataController.addColumn(column2);
boardDataController.addColumn(column3);
super.initState();
}

View File

@ -20,7 +20,7 @@ class _SingleBoardListExampleState extends State<SingleBoardListExample> {
TextItem("d"),
]);
boardData.setColumnData(column);
boardData.addColumn(column);
super.initState();
}

View File

@ -1,6 +1,5 @@
library flowy_board;
export 'src/widgets/board_column/board_column.dart';
export 'src/widgets/board_column/data_controller.dart';
export 'src/widgets/board.dart';
export 'src/widgets/board_column/board_column_data.dart';
export 'src/widgets/board_data.dart';
export 'src/widgets/board.dart';

View File

@ -6,7 +6,7 @@ const DART_LOG = "Dart_LOG";
class Log {
// static const enableLog = bool.hasEnvironment(DART_LOG);
// static final shared = Log();
static const enableLog = true;
static const enableLog = false;
static void info(String? message) {
if (enableLog) {
@ -22,7 +22,7 @@ class Log {
static void trace(String? message) {
if (enableLog) {
debugPrint('❗️[Trace]=> $message');
// debugPrint('❗️[Trace]=> $message');
}
}
}

View File

@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'board_column/board_column.dart';
import 'board_column/board_column_data.dart';
import 'board_data.dart';
import 'flex/drag_target_inteceptor.dart';
import 'flex/reorder_flex.dart';
import 'phantom/phantom_controller.dart';
import '../../flowy_board.dart';
import '../rendering/board_overlay.dart';
class Board extends StatelessWidget {
@ -122,7 +124,8 @@ class BoardContent extends StatefulWidget {
}
class _BoardContentState extends State<BoardContent> {
final GlobalKey _columnContainerOverlayKey = GlobalKey(debugLabel: '$BoardContent overlay key');
final GlobalKey _columnContainerOverlayKey =
GlobalKey(debugLabel: '$BoardContent overlay key');
late BoardOverlayEntry _overlayEntry;
@override
@ -215,7 +218,8 @@ class _BoardColumnDataSourceImpl extends BoardColumnDataDataSource {
});
@override
BoardColumnData get columnData => dataController.columnController(columnId).columnData;
BoardColumnData get columnData =>
dataController.columnController(columnId).columnData;
@override
List<String> get acceptedColumnIds => dataController.columnIds;

View File

@ -6,7 +6,7 @@ import '../../utils/log.dart';
import '../phantom/phantom_controller.dart';
import '../flex/reorder_flex.dart';
import '../flex/drag_target_inteceptor.dart';
import 'data_controller.dart';
import 'board_column_data.dart';
typedef OnColumnDragStarted = void Function(int index);

View File

@ -2,16 +2,33 @@ import 'dart:collection';
import 'package:equatable/equatable.dart';
import '../../flowy_board.dart';
import '../utils/log.dart';
import 'board_column/board_column_data.dart';
import 'flex/reorder_flex.dart';
import 'package:flutter/material.dart';
import 'phantom/phantom_controller.dart';
@protected
typedef OnMoveColumn = void Function(int fromIndex, int toIndex);
typedef OnMoveColumnItem = void Function(
String columnId,
int fromIndex,
int toIndex,
);
typedef OnMoveColumnItemToColumn = void Function(
String fromColumnId,
int fromIndex,
String toColumnId,
int toIndex,
);
class BoardDataController extends ChangeNotifier
with EquatableMixin, BoardPhantomControllerDelegate, ReoderFlextDataSource {
final List<BoardColumnData> _columnDatas = [];
final OnMoveColumn? onMoveColumn;
final OnMoveColumnItem? onMoveColumnItem;
final OnMoveColumnItemToColumn? onMoveColumnItemToColumn;
List<BoardColumnData> get columnDatas => _columnDatas;
@ -21,9 +38,13 @@ class BoardDataController extends ChangeNotifier
final LinkedHashMap<String, BoardColumnDataController> _columnControllers =
LinkedHashMap();
BoardDataController();
BoardDataController({
this.onMoveColumn,
this.onMoveColumnItem,
this.onMoveColumnItemToColumn,
});
void setColumnData(BoardColumnData columnData) {
void addColumn(BoardColumnData columnData) {
final controller = BoardColumnDataController(columnData: columnData);
_columnDatas.add(columnData);
_columnControllers[columnData.id] = controller;
@ -36,6 +57,7 @@ class BoardDataController extends ChangeNotifier
void moveColumn(int fromIndex, int toIndex) {
final columnData = _columnDatas.removeAt(fromIndex);
_columnDatas.insert(toIndex, columnData);
onMoveColumn?.call(fromIndex, toIndex);
notifyListeners();
}
@ -44,10 +66,12 @@ class BoardDataController extends ChangeNotifier
assert(columnController != null);
if (columnController != null) {
columnController.move(fromIndex, toIndex);
onMoveColumnItem?.call(columnId, fromIndex, toIndex);
}
}
@override
@protected
void swapColumnItem(
String fromColumnId,
int fromColumnIndex,
@ -55,11 +79,17 @@ class BoardDataController extends ChangeNotifier
int toColumnIndex,
) {
final item = columnController(fromColumnId).removeAt(fromColumnIndex);
assert(
columnController(toColumnId).items[toColumnIndex] is PhantomColumnItem);
columnController(toColumnId).replace(toColumnIndex, item);
onMoveColumnItemToColumn?.call(
fromColumnId,
fromColumnIndex,
toColumnId,
toColumnIndex,
);
}
@override
@ -80,6 +110,7 @@ class BoardDataController extends ChangeNotifier
UnmodifiableListView(_columnDatas);
@override
@protected
bool removePhantom(String columnId) {
final columnController = this.columnController(columnId);
final index = columnController.items.indexWhere((item) => item.isPhantom);
@ -95,6 +126,7 @@ class BoardDataController extends ChangeNotifier
}
@override
@protected
void updatePhantom(String columnId, int newIndex) {
final columnDataController = columnController(columnId);
final index =
@ -111,6 +143,7 @@ class BoardDataController extends ChangeNotifier
}
@override
@protected
void insertPhantom(String columnId, int index, PhantomColumnItem item) {
columnController(columnId).insert(index, item);
}

View File

@ -327,29 +327,16 @@ class _FakeDragTargetState<T extends DragTargetData>
@override
void initState() {
widget.insertAnimationController.addStatusListener(
(status) {
if (status != AnimationStatus.completed) return;
if (!mounted) return;
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
simulateDragging = true;
widget.deleteAnimationController.reverse(from: 1.0);
widget.onWillAccept(widget.eventData.dragTargetData as T);
widget.onDragStarted(
widget.child,
widget.eventData.index,
widget.eventData.feedbackSize,
);
});
});
},
_onInsertedAnimationStatusChanged,
);
/// Start insert animation
widget.insertAnimationController.forward(from: 0.0);
widget.eventTrigger.fakeOnDragEnded(() {
if (mounted) {
WidgetsBinding.instance.addPostFrameCallback((_) {
widget.onDragEnded(widget.eventData.dragTargetData as T);
}
});
});
super.initState();
@ -357,17 +344,40 @@ class _FakeDragTargetState<T extends DragTargetData>
@override
Widget build(BuildContext context) {
final child = IgnorePointerWidget(
useIntrinsicSize: !simulateDragging, child: widget.child);
if (simulateDragging) {
return SizeTransitionWithIntrinsicSize(
sizeFactor: widget.deleteAnimationController,
axis: Axis.vertical,
child: IgnorePointerWidget(
child: widget.child,
),
);
} else {
return SizeTransitionWithIntrinsicSize(
sizeFactor: widget.insertAnimationController,
axis: Axis.vertical,
child: IgnorePointerWidget(
useIntrinsicSize: true,
child: widget.child,
),
);
}
}
final animationController = simulateDragging
? widget.deleteAnimationController
: widget.insertAnimationController;
return SizeTransitionWithIntrinsicSize(
sizeFactor: animationController,
axis: Axis.vertical,
child: child,
);
void _onInsertedAnimationStatusChanged(AnimationStatus status) {
if (status != AnimationStatus.completed) return;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
setState(() {
simulateDragging = true;
widget.deleteAnimationController.reverse(from: 1.0);
widget.onWillAccept(widget.eventData.dragTargetData as T);
widget.onDragStarted(
widget.child,
widget.eventData.index,
widget.eventData.feedbackSize,
);
});
});
}
}

View File

@ -27,8 +27,10 @@ mixin ReorderFlexMinxi {
child: FadeTransition(opacity: animationController, child: child),
);
BoxConstraints contentSizeConstraints = BoxConstraints.loose(draggingFeedbackSize);
return ConstrainedBox(constraints: contentSizeConstraints, child: transition);
BoxConstraints contentSizeConstraints =
BoxConstraints.loose(draggingFeedbackSize);
return ConstrainedBox(
constraints: contentSizeConstraints, child: transition);
}
}
@ -56,13 +58,16 @@ mixin ReorderFlexMinxi {
child: FadeTransition(opacity: animationController, child: child),
);
BoxConstraints contentSizeConstraints = BoxConstraints.loose(draggingFeedbackSize);
return ConstrainedBox(constraints: contentSizeConstraints, child: transition);
BoxConstraints contentSizeConstraints =
BoxConstraints.loose(draggingFeedbackSize);
return ConstrainedBox(
constraints: contentSizeConstraints, child: transition);
}
}
}
Animation<double> withCurve(AnimationController animationController, Cubic curve) {
Animation<double> withCurve(
AnimationController animationController, Cubic curve) {
return CurvedAnimation(
parent: animationController,
curve: curve,

View File

@ -1,12 +1,11 @@
import 'package:flutter/material.dart';
import '../../../flowy_board.dart';
import '../../utils/log.dart';
import '../board_column/board_column_data.dart';
import '../flex/drag_state.dart';
import '../flex/drag_target.dart';
import '../flex/drag_target_inteceptor.dart';
import 'phantom_state.dart';
@protected
abstract class BoardPhantomControllerDelegate {
BoardColumnDataController? controller(String columnId);
@ -35,7 +34,6 @@ abstract class BoardPhantomControllerDelegate {
);
}
@protected
class BoardPhantomController extends OverlapDragTargetDelegate
with CrossReorderFlexDragTargetDelegate {
PhantomRecord? phantomRecord;
@ -95,8 +93,6 @@ class BoardPhantomController extends OverlapDragTargetDelegate
/// Remove the phantom in the column if it contains phantom
void _removePhantom(String columnId) {
// columnsState.notifyDidRemovePhantom(columnId);
// columnsState.removeColumnListener(columnId);
if (delegate.removePhantom(columnId)) {
columnsState.notifyDidRemovePhantom(columnId);
columnsState.removeColumnListener(columnId);
@ -217,7 +213,6 @@ class BoardPhantomController extends OverlapDragTargetDelegate
/// [toColumnId] the column that the phantom moves into
/// [toColumnIndex] the index of the phantom moves into the column
///
@protected
class PhantomRecord {
final String fromColumnId;
int fromColumnIndex;
@ -313,7 +308,6 @@ class PassthroughPhantomContext extends FakeDragTargetEventTrigger
}
}
@protected
class PassthroughPhantomWidget extends PhantomWidget {
final PassthroughPhantomContext passthroughPhantomContext;
@ -328,7 +322,6 @@ class PassthroughPhantomWidget extends PhantomWidget {
);
}
@protected
class PhantomDraggableBuilder extends ReorderFlexDraggableTargetBuilder {
PhantomDraggableBuilder();
@override