@@ -28,16 +28,42 @@ typedef OnMoveGroupItemToGroup = void Function(
2828 int toIndex,
2929);
3030
31+ /// A controller for [AppFlowyBoard] widget.
32+ ///
33+ /// A [AppFlowyBoardDataController] can be used to provide an initial value of
34+ /// the board by calling [addGroup] method with the passed in parameter
35+ /// [AppFlowyBoardGroupData] . A [AppFlowyBoardGroupData] represents one
36+ /// group data. Whenever the user modifies the board, this controller will
37+ /// update the corresponding group data.
38+ ///
39+ /// Also, you can register the callbacks that receive the changes.
40+ /// [onMoveGroup] will get called when moving the group from one position to
41+ /// another.
42+ ///
43+ /// [onMoveGroupItem] will get called when moving the group's items.
44+ ///
45+ /// [onMoveGroupItemToGroup] will get called when moving the group's item from
46+ /// one group to another group.
3147class AppFlowyBoardDataController extends ChangeNotifier
3248 with EquatableMixin , BoardPhantomControllerDelegate , ReoderFlexDataSource {
3349 final List <AppFlowyBoardGroupData > _groupDatas = [];
50+
51+ /// [onMoveGroup] will get called when moving the group from one position to
52+ /// another.
3453 final OnMoveGroup ? onMoveGroup;
54+
55+ /// [onMoveGroupItem] will get called when moving the group's items.
3556 final OnMoveGroupItem ? onMoveGroupItem;
57+
58+ /// [onMoveGroupItemToGroup] will get called when moving the group's item from
59+ /// one group to another group.
3660 final OnMoveGroupItemToGroup ? onMoveGroupItemToGroup;
3761
62+ /// Returns the unmodifiable list of [AppFlowyBoardGroupData]
3863 UnmodifiableListView <AppFlowyBoardGroupData > get groupDatas =>
3964 UnmodifiableListView (_groupDatas);
4065
66+ /// Returns list of group id
4167 List <String > get groupIds =>
4268 _groupDatas.map ((groupData) => groupData.id).toList ();
4369
@@ -50,6 +76,10 @@ class AppFlowyBoardDataController extends ChangeNotifier
5076 this .onMoveGroupItemToGroup,
5177 });
5278
79+ /// Adds a new group to the end of the current group list.
80+ ///
81+ /// If you don't want to notify the listener after adding a new group, the
82+ /// [notify] should set to false. Default value is true.
5383 void addGroup (AppFlowyBoardGroupData groupData, {bool notify = true }) {
5484 if (_groupControllers[groupData.id] != null ) return ;
5585
@@ -59,6 +89,10 @@ class AppFlowyBoardDataController extends ChangeNotifier
5989 if (notify) notifyListeners ();
6090 }
6191
92+ /// Adds a list of groups to the end of the current group list.
93+ ///
94+ /// If you don't want to notify the listener after adding the groups, the
95+ /// [notify] should set to false. Default value is true.
6296 void addGroups (List <AppFlowyBoardGroupData > groups, {bool notify = true }) {
6397 for (final column in groups) {
6498 addGroup (column, notify: false );
@@ -67,6 +101,10 @@ class AppFlowyBoardDataController extends ChangeNotifier
67101 if (groups.isNotEmpty && notify) notifyListeners ();
68102 }
69103
104+ /// Removes the group with id [groupId]
105+ ///
106+ /// If you don't want to notify the listener after removing the group, the
107+ /// [notify] should set to false. Default value is true.
70108 void removeGroup (String groupId, {bool notify = true }) {
71109 final index = _groupDatas.indexWhere ((group) => group.id == groupId);
72110 if (index == - 1 ) {
@@ -82,6 +120,10 @@ class AppFlowyBoardDataController extends ChangeNotifier
82120 }
83121 }
84122
123+ /// Removes a list of groups
124+ ///
125+ /// If you don't want to notify the listener after removing the groups, the
126+ /// [notify] should set to false. Default value is true.
85127 void removeGroups (List <String > groupIds, {bool notify = true }) {
86128 for (final groupId in groupIds) {
87129 removeGroup (groupId, notify: false );
@@ -90,12 +132,16 @@ class AppFlowyBoardDataController extends ChangeNotifier
90132 if (groupIds.isNotEmpty && notify) notifyListeners ();
91133 }
92134
135+ /// Remove all the groups controller.
136+ /// This method should get called when you want to remove all the current
137+ /// groups or get ready to reinitialize the [AppFlowyBoard] .
93138 void clear () {
94139 _groupDatas.clear ();
95140 _groupControllers.clear ();
96141 notifyListeners ();
97142 }
98143
144+ /// Returns the [AFBoardGroupDataController] with id [groupId] .
99145 AFBoardGroupDataController ? getGroupController (String groupId) {
100146 final groupController = _groupControllers[groupId];
101147 if (groupController == null ) {
@@ -105,6 +151,11 @@ class AppFlowyBoardDataController extends ChangeNotifier
105151 return groupController;
106152 }
107153
154+ /// Moves the group controller from [fromIndex] to [toIndex] and notify the
155+ /// listeners.
156+ ///
157+ /// If you don't want to notify the listener after moving the group, the
158+ /// [notify] should set to false. Default value is true.
108159 void moveGroup (int fromIndex, int toIndex, {bool notify = true }) {
109160 final toGroupData = _groupDatas[toIndex];
110161 final fromGroupData = _groupDatas.removeAt (fromIndex);
@@ -114,44 +165,55 @@ class AppFlowyBoardDataController extends ChangeNotifier
114165 if (notify) notifyListeners ();
115166 }
116167
168+ /// Moves the group's item from [fromIndex] to [toIndex]
169+ /// If the group with id [groupId] is not exist, this method will do nothing.
117170 void moveGroupItem (String groupId, int fromIndex, int toIndex) {
118171 if (getGroupController (groupId)? .move (fromIndex, toIndex) ?? false ) {
119172 onMoveGroupItem? .call (groupId, fromIndex, toIndex);
120173 }
121174 }
122175
176+ /// Adds the [AppFlowyGroupItem] to the end of the group
177+ /// If the group with id [groupId] is not exist, this method will do nothing.
123178 void addGroupItem (String groupId, AppFlowyGroupItem item) {
124179 getGroupController (groupId)? .add (item);
125180 }
126181
182+ /// Inserts the [AppFlowyGroupItem] at [index] in the group
183+ /// It will do nothing if the group with id [groupId] is not exist
127184 void insertGroupItem (String groupId, int index, AppFlowyGroupItem item) {
128185 getGroupController (groupId)? .insert (index, item);
129186 }
130187
188+ /// Removes the item with id [itemId] from the group
189+ /// It will do nothing if the group with id [groupId] is not exist
131190 void removeGroupItem (String groupId, String itemId) {
132191 getGroupController (groupId)? .removeWhere ((item) => item.id == itemId);
133192 }
134193
194+ /// Replaces or inserts the [AppFlowyGroupItem] to the end of the group.
195+ /// If the group with id [groupId] is not exist, this method will do nothing.
135196 void updateGroupItem (String groupId, AppFlowyGroupItem item) {
136197 getGroupController (groupId)? .replaceOrInsertItem (item);
137198 }
138199
200+ /// Swap the
139201 @override
140202 @protected
141- void swapGroupItem (
203+ void moveGroupItemToAnotherGroup (
142204 String fromGroupId,
143205 int fromGroupIndex,
144206 String toGroupId,
145207 int toGroupIndex,
146208 ) {
147209 final fromGroupController = getGroupController (fromGroupId)! ;
148210 final toGroupController = getGroupController (toGroupId)! ;
149- final item = fromGroupController.removeAt (fromGroupIndex);
211+ final fromGroupItem = fromGroupController.removeAt (fromGroupIndex);
150212 if (toGroupController.items.length > toGroupIndex) {
151213 assert (toGroupController.items[toGroupIndex] is PhantomGroupItem );
152214 }
153215
154- toGroupController.replace (toGroupIndex, item );
216+ toGroupController.replace (toGroupIndex, fromGroupItem );
155217 onMoveGroupItemToGroup? .call (
156218 fromGroupId,
157219 fromGroupIndex,
0 commit comments