|
@@ -28,16 +28,42 @@ typedef OnMoveGroupItemToGroup = void Function(
|
|
|
int toIndex,
|
|
|
);
|
|
|
|
|
|
+/// A controller for [AppFlowyBoard] widget.
|
|
|
+///
|
|
|
+/// A [AppFlowyBoardDataController] can be used to provide an initial value of
|
|
|
+/// the board by calling [addGroup] method with the passed in parameter
|
|
|
+/// [AppFlowyBoardGroupData]. A [AppFlowyBoardGroupData] represents one
|
|
|
+/// group data. Whenever the user modifies the board, this controller will
|
|
|
+/// update the corresponding group data.
|
|
|
+///
|
|
|
+/// Also, you can register the callbacks that receive the changes.
|
|
|
+/// [onMoveGroup] will get called when moving the group from one position to
|
|
|
+/// another.
|
|
|
+///
|
|
|
+/// [onMoveGroupItem] will get called when moving the group's items.
|
|
|
+///
|
|
|
+/// [onMoveGroupItemToGroup] will get called when moving the group's item from
|
|
|
+/// one group to another group.
|
|
|
class AppFlowyBoardDataController extends ChangeNotifier
|
|
|
with EquatableMixin, BoardPhantomControllerDelegate, ReoderFlexDataSource {
|
|
|
final List<AppFlowyBoardGroupData> _groupDatas = [];
|
|
|
+
|
|
|
+ /// [onMoveGroup] will get called when moving the group from one position to
|
|
|
+ /// another.
|
|
|
final OnMoveGroup? onMoveGroup;
|
|
|
+
|
|
|
+ /// [onMoveGroupItem] will get called when moving the group's items.
|
|
|
final OnMoveGroupItem? onMoveGroupItem;
|
|
|
+
|
|
|
+ /// [onMoveGroupItemToGroup] will get called when moving the group's item from
|
|
|
+ /// one group to another group.
|
|
|
final OnMoveGroupItemToGroup? onMoveGroupItemToGroup;
|
|
|
|
|
|
+ /// Returns the unmodifiable list of [AppFlowyBoardGroupData]
|
|
|
UnmodifiableListView<AppFlowyBoardGroupData> get groupDatas =>
|
|
|
UnmodifiableListView(_groupDatas);
|
|
|
|
|
|
+ /// Returns list of group id
|
|
|
List<String> get groupIds =>
|
|
|
_groupDatas.map((groupData) => groupData.id).toList();
|
|
|
|
|
@@ -50,6 +76,10 @@ class AppFlowyBoardDataController extends ChangeNotifier
|
|
|
this.onMoveGroupItemToGroup,
|
|
|
});
|
|
|
|
|
|
+ /// Adds a new group to the end of the current group list.
|
|
|
+ ///
|
|
|
+ /// If you don't want to notify the listener after adding a new group, the
|
|
|
+ /// [notify] should set to false. Default value is true.
|
|
|
void addGroup(AppFlowyBoardGroupData groupData, {bool notify = true}) {
|
|
|
if (_groupControllers[groupData.id] != null) return;
|
|
|
|
|
@@ -59,6 +89,10 @@ class AppFlowyBoardDataController extends ChangeNotifier
|
|
|
if (notify) notifyListeners();
|
|
|
}
|
|
|
|
|
|
+ /// Adds a list of groups to the end of the current group list.
|
|
|
+ ///
|
|
|
+ /// If you don't want to notify the listener after adding the groups, the
|
|
|
+ /// [notify] should set to false. Default value is true.
|
|
|
void addGroups(List<AppFlowyBoardGroupData> groups, {bool notify = true}) {
|
|
|
for (final column in groups) {
|
|
|
addGroup(column, notify: false);
|
|
@@ -67,6 +101,10 @@ class AppFlowyBoardDataController extends ChangeNotifier
|
|
|
if (groups.isNotEmpty && notify) notifyListeners();
|
|
|
}
|
|
|
|
|
|
+ /// Removes the group with id [groupId]
|
|
|
+ ///
|
|
|
+ /// If you don't want to notify the listener after removing the group, the
|
|
|
+ /// [notify] should set to false. Default value is true.
|
|
|
void removeGroup(String groupId, {bool notify = true}) {
|
|
|
final index = _groupDatas.indexWhere((group) => group.id == groupId);
|
|
|
if (index == -1) {
|
|
@@ -82,6 +120,10 @@ class AppFlowyBoardDataController extends ChangeNotifier
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// Removes a list of groups
|
|
|
+ ///
|
|
|
+ /// If you don't want to notify the listener after removing the groups, the
|
|
|
+ /// [notify] should set to false. Default value is true.
|
|
|
void removeGroups(List<String> groupIds, {bool notify = true}) {
|
|
|
for (final groupId in groupIds) {
|
|
|
removeGroup(groupId, notify: false);
|
|
@@ -90,12 +132,16 @@ class AppFlowyBoardDataController extends ChangeNotifier
|
|
|
if (groupIds.isNotEmpty && notify) notifyListeners();
|
|
|
}
|
|
|
|
|
|
+ /// Remove all the groups controller.
|
|
|
+ /// This method should get called when you want to remove all the current
|
|
|
+ /// groups or get ready to reinitialize the [AppFlowyBoard].
|
|
|
void clear() {
|
|
|
_groupDatas.clear();
|
|
|
_groupControllers.clear();
|
|
|
notifyListeners();
|
|
|
}
|
|
|
|
|
|
+ /// Returns the [AFBoardGroupDataController] with id [groupId].
|
|
|
AFBoardGroupDataController? getGroupController(String groupId) {
|
|
|
final groupController = _groupControllers[groupId];
|
|
|
if (groupController == null) {
|
|
@@ -105,6 +151,11 @@ class AppFlowyBoardDataController extends ChangeNotifier
|
|
|
return groupController;
|
|
|
}
|
|
|
|
|
|
+ /// Moves the group controller from [fromIndex] to [toIndex] and notify the
|
|
|
+ /// listeners.
|
|
|
+ ///
|
|
|
+ /// If you don't want to notify the listener after moving the group, the
|
|
|
+ /// [notify] should set to false. Default value is true.
|
|
|
void moveGroup(int fromIndex, int toIndex, {bool notify = true}) {
|
|
|
final toGroupData = _groupDatas[toIndex];
|
|
|
final fromGroupData = _groupDatas.removeAt(fromIndex);
|
|
@@ -114,31 +165,42 @@ class AppFlowyBoardDataController extends ChangeNotifier
|
|
|
if (notify) notifyListeners();
|
|
|
}
|
|
|
|
|
|
+ /// Moves the group's item from [fromIndex] to [toIndex]
|
|
|
+ /// If the group with id [groupId] is not exist, this method will do nothing.
|
|
|
void moveGroupItem(String groupId, int fromIndex, int toIndex) {
|
|
|
if (getGroupController(groupId)?.move(fromIndex, toIndex) ?? false) {
|
|
|
onMoveGroupItem?.call(groupId, fromIndex, toIndex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// Adds the [AppFlowyGroupItem] to the end of the group
|
|
|
+ /// If the group with id [groupId] is not exist, this method will do nothing.
|
|
|
void addGroupItem(String groupId, AppFlowyGroupItem item) {
|
|
|
getGroupController(groupId)?.add(item);
|
|
|
}
|
|
|
|
|
|
+ /// Inserts the [AppFlowyGroupItem] at [index] in the group
|
|
|
+ /// It will do nothing if the group with id [groupId] is not exist
|
|
|
void insertGroupItem(String groupId, int index, AppFlowyGroupItem item) {
|
|
|
getGroupController(groupId)?.insert(index, item);
|
|
|
}
|
|
|
|
|
|
+ /// Removes the item with id [itemId] from the group
|
|
|
+ /// It will do nothing if the group with id [groupId] is not exist
|
|
|
void removeGroupItem(String groupId, String itemId) {
|
|
|
getGroupController(groupId)?.removeWhere((item) => item.id == itemId);
|
|
|
}
|
|
|
|
|
|
+ /// Replaces or inserts the [AppFlowyGroupItem] to the end of the group.
|
|
|
+ /// If the group with id [groupId] is not exist, this method will do nothing.
|
|
|
void updateGroupItem(String groupId, AppFlowyGroupItem item) {
|
|
|
getGroupController(groupId)?.replaceOrInsertItem(item);
|
|
|
}
|
|
|
|
|
|
+ /// Swap the
|
|
|
@override
|
|
|
@protected
|
|
|
- void swapGroupItem(
|
|
|
+ void moveGroupItemToAnotherGroup(
|
|
|
String fromGroupId,
|
|
|
int fromGroupIndex,
|
|
|
String toGroupId,
|
|
@@ -146,12 +208,12 @@ class AppFlowyBoardDataController extends ChangeNotifier
|
|
|
) {
|
|
|
final fromGroupController = getGroupController(fromGroupId)!;
|
|
|
final toGroupController = getGroupController(toGroupId)!;
|
|
|
- final item = fromGroupController.removeAt(fromGroupIndex);
|
|
|
+ final fromGroupItem = fromGroupController.removeAt(fromGroupIndex);
|
|
|
if (toGroupController.items.length > toGroupIndex) {
|
|
|
assert(toGroupController.items[toGroupIndex] is PhantomGroupItem);
|
|
|
}
|
|
|
|
|
|
- toGroupController.replace(toGroupIndex, item);
|
|
|
+ toGroupController.replace(toGroupIndex, fromGroupItem);
|
|
|
onMoveGroupItemToGroup?.call(
|
|
|
fromGroupId,
|
|
|
fromGroupIndex,
|