Skip to content

Commit 8f5569a

Browse files
committed
chore: update doc
1 parent c7fdfb4 commit 8f5569a

File tree

4 files changed

+82
-29
lines changed

4 files changed

+82
-29
lines changed

frontend/app_flowy/packages/appflowy_board/lib/src/widgets/board.dart

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class AppFlowyBoard extends StatelessWidget {
110110
scrollManager!._groupState = _groupState;
111111
}
112112

113-
return AFBoardContent(
113+
return _AppFlolwyBoardContent(
114114
config: config,
115115
dataController: dataController,
116116
scrollController: scrollController,
@@ -131,7 +131,7 @@ class AppFlowyBoard extends StatelessWidget {
131131
}
132132
}
133133

134-
class AFBoardContent extends StatefulWidget {
134+
class _AppFlolwyBoardContent extends StatefulWidget {
135135
final ScrollController? scrollController;
136136
final OnDragStarted? onDragStarted;
137137
final OnReorder onReorder;
@@ -143,21 +143,13 @@ class AFBoardContent extends StatefulWidget {
143143
final BoxConstraints columnConstraints;
144144
final AFBoardScrollManager? scrollManager;
145145
final BoardGroupsState columnsState;
146-
147-
///
148146
final AppFlowyBoardCardBuilder cardBuilder;
149-
150-
///
151147
final AppFlowyBoardHeaderBuilder? headerBuilder;
152-
153-
///
154148
final AppFlowyBoardFooterBuilder? footerBuilder;
155-
156149
final OverlapDragTargetDelegate delegate;
157-
158150
final BoardPhantomController phantomController;
159151

160-
const AFBoardContent({
152+
const _AppFlolwyBoardContent({
161153
required this.config,
162154
required this.onReorder,
163155
required this.delegate,
@@ -178,12 +170,12 @@ class AFBoardContent extends StatefulWidget {
178170
super(key: key);
179171

180172
@override
181-
State<AFBoardContent> createState() => _AFBoardContentState();
173+
State<_AppFlolwyBoardContent> createState() => _AppFlowyBoardContentState();
182174
}
183175

184-
class _AFBoardContentState extends State<AFBoardContent> {
176+
class _AppFlowyBoardContentState extends State<_AppFlolwyBoardContent> {
185177
final GlobalKey _boardContentKey =
186-
GlobalKey(debugLabel: '$AFBoardContent overlay key');
178+
GlobalKey(debugLabel: '$_AppFlolwyBoardContent overlay key');
187179
late BoardOverlayEntry _overlayEntry;
188180

189181
final Map<String, GlobalObjectKey> _reorderFlexKeys = {};
@@ -263,7 +255,7 @@ class _AFBoardContentState extends State<AFBoardContent> {
263255
value: widget.dataController.getGroupController(columnData.id),
264256
child: Consumer<AFBoardGroupDataController>(
265257
builder: (context, value, child) {
266-
final boardColumn = AppFlowyBoardGroupWidget(
258+
final boardColumn = AppFlowyBoardGroup(
267259
reorderFlexKey: reorderFlexKey,
268260
// key: PageStorageKey<String>(columnData.id),
269261
margin: _marginFromIndex(columnIndex),
@@ -351,12 +343,12 @@ class BoardGroupContext {
351343

352344
class BoardGroupsState extends DraggingStateStorage
353345
with ReorderDragTargetIndexKeyStorage {
354-
/// Quick access to the [AppFlowyBoardGroupWidget]
346+
/// Quick access to the [AppFlowyBoardGroup]
355347
final Map<String, GlobalKey> groupKeys = {};
356348
final Map<String, DraggingState> groupDragStates = {};
357349
final Map<String, Map<String, GlobalObjectKey>> groupDragDragTargets = {};
358350

359-
void addGroup(String groupId, AppFlowyBoardGroupWidget groupWidget) {
351+
void addGroup(String groupId, AppFlowyBoardGroup groupWidget) {
360352
groupKeys[groupId] = groupWidget.reorderFlexKey;
361353
}
362354

frontend/app_flowy/packages/appflowy_board/lib/src/widgets/board_column/board_column.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ abstract class AppFlowyBoardGroupDataDataSource extends ReoderFlexDataSource {
6060
}
6161
}
6262

63-
/// [AppFlowyBoardGroupWidget] represents the column of the Board.
63+
/// [AppFlowyBoardGroup] represents the group of the Board.
6464
///
65-
class AppFlowyBoardGroupWidget extends StatefulWidget {
65+
class AppFlowyBoardGroup extends StatefulWidget {
6666
final AppFlowyBoardGroupDataDataSource dataSource;
6767
final ScrollController? scrollController;
6868
final ReorderFlexConfig config;
@@ -94,7 +94,7 @@ class AppFlowyBoardGroupWidget extends StatefulWidget {
9494

9595
final GlobalObjectKey reorderFlexKey;
9696

97-
const AppFlowyBoardGroupWidget({
97+
const AppFlowyBoardGroup({
9898
Key? key,
9999
required this.reorderFlexKey,
100100
this.headerBuilder,
@@ -116,13 +116,12 @@ class AppFlowyBoardGroupWidget extends StatefulWidget {
116116
super(key: key);
117117

118118
@override
119-
State<AppFlowyBoardGroupWidget> createState() =>
120-
_AppFlowyBoardGroupWidgetState();
119+
State<AppFlowyBoardGroup> createState() => _AppFlowyBoardGroupState();
121120
}
122121

123-
class _AppFlowyBoardGroupWidgetState extends State<AppFlowyBoardGroupWidget> {
122+
class _AppFlowyBoardGroupState extends State<AppFlowyBoardGroup> {
124123
final GlobalKey _columnOverlayKey =
125-
GlobalKey(debugLabel: '$AppFlowyBoardGroupWidget overlay key');
124+
GlobalKey(debugLabel: '$AppFlowyBoardGroup overlay key');
126125
late BoardOverlayEntry _overlayEntry;
127126

128127
@override

frontend/app_flowy/packages/appflowy_board/lib/src/widgets/board_data.dart

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
3147
class 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,

frontend/app_flowy/packages/appflowy_board/lib/src/widgets/reorder_phantom/phantom_controller.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class BoardPhantomControllerDelegate {
2727
/// [dragTargetIndex] the index of the dragTarget
2828
void updatePhantom(String groupId, int newIndex);
2929

30-
void swapGroupItem(
30+
void moveGroupItemToAnotherGroup(
3131
String fromGroupId,
3232
int fromGroupIndex,
3333
String toGroupId,
@@ -79,7 +79,7 @@ class BoardPhantomController extends OverlapDragTargetDelegate
7979
}
8080

8181
if (phantomRecord!.toGroupId == groupId) {
82-
delegate.swapGroupItem(
82+
delegate.moveGroupItemToAnotherGroup(
8383
fromGroupId,
8484
phantomRecord!.fromGroupIndex,
8585
toGroupId,

0 commit comments

Comments
 (0)