Skip to content

Commit a800e01

Browse files
committed
chore: config checklist board UI
1 parent 29e0708 commit a800e01

File tree

5 files changed

+45
-16
lines changed

5 files changed

+45
-16
lines changed
Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
1+
import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart';
2+
import 'package:app_flowy/plugins/grid/application/cell/checklist_cell_bloc.dart';
3+
import 'package:app_flowy/plugins/grid/presentation/widgets/cell/checklist_cell/checklist_cell.dart';
14
import 'package:flutter/material.dart';
5+
import 'package:flutter_bloc/flutter_bloc.dart';
26

3-
class BoardChecklistCell extends StatelessWidget {
4-
const BoardChecklistCell({Key? key}) : super(key: key);
7+
class BoardChecklistCell extends StatefulWidget {
8+
final GridCellControllerBuilder cellControllerBuilder;
9+
const BoardChecklistCell({required this.cellControllerBuilder, Key? key})
10+
: super(key: key);
11+
12+
@override
13+
State<BoardChecklistCell> createState() => _BoardChecklistCellState();
14+
}
15+
16+
class _BoardChecklistCellState extends State<BoardChecklistCell> {
17+
late ChecklistCellBloc _cellBloc;
18+
19+
@override
20+
void initState() {
21+
final cellController =
22+
widget.cellControllerBuilder.build() as GridChecklistCellController;
23+
_cellBloc = ChecklistCellBloc(cellController: cellController);
24+
_cellBloc.add(const ChecklistCellEvent.initial());
25+
super.initState();
26+
}
527

628
@override
729
Widget build(BuildContext context) {
8-
return Container();
30+
return BlocProvider.value(
31+
value: _cellBloc,
32+
child: const ChecklistProgressBar(),
33+
);
934
}
1035
}

frontend/app_flowy/lib/plugins/board/presentation/card/card_cell_builder.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class BoardCellBuilder {
6161
);
6262
case FieldType.Checklist:
6363
return BoardChecklistCell(
64+
cellControllerBuilder: cellControllerBuilder,
6465
key: key,
6566
);
6667
case FieldType.Number:

frontend/app_flowy/lib/plugins/grid/application/cell/checklist_cell_bloc.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
44
import 'package:freezed_annotation/freezed_annotation.dart';
55
import 'dart:async';
66
import 'cell_service/cell_service.dart';
7+
import 'checklist_cell_editor_bloc.dart';
78
import 'select_option_service.dart';
89
part 'checklist_cell_bloc.freezed.dart';
910

@@ -27,8 +28,7 @@ class ChecklistCellBloc extends Bloc<ChecklistCellEvent, ChecklistCellState> {
2728
emit(state.copyWith(
2829
allOptions: data.options,
2930
selectedOptions: data.selectOptions,
30-
percent: data.selectOptions.length.toDouble() /
31-
data.options.length.toDouble(),
31+
percent: percentFromSelectOptionCellData(data),
3232
));
3333
},
3434
);

frontend/app_flowy/lib/plugins/grid/application/cell/checklist_cell_editor_bloc.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ class ChecklistCellEditorBloc
2626
await event.when(
2727
initial: () async {
2828
_startListening();
29+
_loadOptions();
2930
},
3031
didReceiveOptions: (data) {
3132
emit(state.copyWith(
3233
allOptions: _makeChecklistSelectOptions(data, state.predicate),
33-
percent: _percentFromSelectOptionCellData(data),
34+
percent: percentFromSelectOptionCellData(data),
3435
));
3536
},
3637
newOption: (optionName) {
@@ -143,18 +144,21 @@ class ChecklistCellEditorState with _$ChecklistCellEditorState {
143144
return ChecklistCellEditorState(
144145
allOptions: _makeChecklistSelectOptions(data, ''),
145146
createOption: none(),
146-
percent: _percentFromSelectOptionCellData(data),
147+
percent: percentFromSelectOptionCellData(data),
147148
predicate: '',
148149
);
149150
}
150151
}
151152

152-
double _percentFromSelectOptionCellData(SelectOptionCellDataPB? data) {
153+
double percentFromSelectOptionCellData(SelectOptionCellDataPB? data) {
153154
if (data == null) return 0;
154155

155-
final a = data.selectOptions.length.toDouble();
156156
final b = data.options.length.toDouble();
157+
if (b == 0) {
158+
return 0;
159+
}
157160

161+
final a = data.selectOptions.length.toDouble();
158162
if (a > b) return 1.0;
159163

160164
return a / b;

frontend/app_flowy/lib/plugins/grid/presentation/widgets/cell/checklist_cell/checklist_prograss_bar.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class _SliverChecklistPrograssBarDelegate
4242
extends SliverPersistentHeaderDelegate {
4343
_SliverChecklistPrograssBarDelegate();
4444

45-
double fixHeight = 60;
45+
double fixHeight = 54;
4646

4747
@override
4848
Widget build(
@@ -68,11 +68,10 @@ class _SliverChecklistPrograssBarDelegate
6868
.add(ChecklistCellEditorEvent.newOption(text));
6969
},
7070
),
71-
if (state.percent != 0)
72-
Padding(
73-
padding: const EdgeInsets.symmetric(vertical: 8.0),
74-
child: ChecklistPrograssBar(percent: state.percent),
75-
),
71+
Padding(
72+
padding: const EdgeInsets.only(top: 10.0),
73+
child: ChecklistPrograssBar(percent: state.percent),
74+
),
7675
],
7776
),
7877
);
@@ -88,6 +87,6 @@ class _SliverChecklistPrograssBarDelegate
8887

8988
@override
9089
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
91-
return false;
90+
return true;
9291
}
9392
}

0 commit comments

Comments
 (0)