chore: config checklist board UI

This commit is contained in:
nathan
2022-11-30 14:44:55 +08:00
parent 29e07089ca
commit a800e01f0b
5 changed files with 45 additions and 16 deletions

View File

@ -1,10 +1,35 @@
import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart';
import 'package:app_flowy/plugins/grid/application/cell/checklist_cell_bloc.dart';
import 'package:app_flowy/plugins/grid/presentation/widgets/cell/checklist_cell/checklist_cell.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class BoardChecklistCell extends StatelessWidget { class BoardChecklistCell extends StatefulWidget {
const BoardChecklistCell({Key? key}) : super(key: key); final GridCellControllerBuilder cellControllerBuilder;
const BoardChecklistCell({required this.cellControllerBuilder, Key? key})
: super(key: key);
@override
State<BoardChecklistCell> createState() => _BoardChecklistCellState();
}
class _BoardChecklistCellState extends State<BoardChecklistCell> {
late ChecklistCellBloc _cellBloc;
@override
void initState() {
final cellController =
widget.cellControllerBuilder.build() as GridChecklistCellController;
_cellBloc = ChecklistCellBloc(cellController: cellController);
_cellBloc.add(const ChecklistCellEvent.initial());
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container(); return BlocProvider.value(
value: _cellBloc,
child: const ChecklistProgressBar(),
);
} }
} }

View File

@ -61,6 +61,7 @@ class BoardCellBuilder {
); );
case FieldType.Checklist: case FieldType.Checklist:
return BoardChecklistCell( return BoardChecklistCell(
cellControllerBuilder: cellControllerBuilder,
key: key, key: key,
); );
case FieldType.Number: case FieldType.Number:

View File

@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
import 'dart:async'; import 'dart:async';
import 'cell_service/cell_service.dart'; import 'cell_service/cell_service.dart';
import 'checklist_cell_editor_bloc.dart';
import 'select_option_service.dart'; import 'select_option_service.dart';
part 'checklist_cell_bloc.freezed.dart'; part 'checklist_cell_bloc.freezed.dart';
@ -27,8 +28,7 @@ class ChecklistCellBloc extends Bloc<ChecklistCellEvent, ChecklistCellState> {
emit(state.copyWith( emit(state.copyWith(
allOptions: data.options, allOptions: data.options,
selectedOptions: data.selectOptions, selectedOptions: data.selectOptions,
percent: data.selectOptions.length.toDouble() / percent: percentFromSelectOptionCellData(data),
data.options.length.toDouble(),
)); ));
}, },
); );

View File

@ -26,11 +26,12 @@ class ChecklistCellEditorBloc
await event.when( await event.when(
initial: () async { initial: () async {
_startListening(); _startListening();
_loadOptions();
}, },
didReceiveOptions: (data) { didReceiveOptions: (data) {
emit(state.copyWith( emit(state.copyWith(
allOptions: _makeChecklistSelectOptions(data, state.predicate), allOptions: _makeChecklistSelectOptions(data, state.predicate),
percent: _percentFromSelectOptionCellData(data), percent: percentFromSelectOptionCellData(data),
)); ));
}, },
newOption: (optionName) { newOption: (optionName) {
@ -143,18 +144,21 @@ class ChecklistCellEditorState with _$ChecklistCellEditorState {
return ChecklistCellEditorState( return ChecklistCellEditorState(
allOptions: _makeChecklistSelectOptions(data, ''), allOptions: _makeChecklistSelectOptions(data, ''),
createOption: none(), createOption: none(),
percent: _percentFromSelectOptionCellData(data), percent: percentFromSelectOptionCellData(data),
predicate: '', predicate: '',
); );
} }
} }
double _percentFromSelectOptionCellData(SelectOptionCellDataPB? data) { double percentFromSelectOptionCellData(SelectOptionCellDataPB? data) {
if (data == null) return 0; if (data == null) return 0;
final a = data.selectOptions.length.toDouble();
final b = data.options.length.toDouble(); final b = data.options.length.toDouble();
if (b == 0) {
return 0;
}
final a = data.selectOptions.length.toDouble();
if (a > b) return 1.0; if (a > b) return 1.0;
return a / b; return a / b;

View File

@ -42,7 +42,7 @@ class _SliverChecklistPrograssBarDelegate
extends SliverPersistentHeaderDelegate { extends SliverPersistentHeaderDelegate {
_SliverChecklistPrograssBarDelegate(); _SliverChecklistPrograssBarDelegate();
double fixHeight = 60; double fixHeight = 54;
@override @override
Widget build( Widget build(
@ -68,9 +68,8 @@ class _SliverChecklistPrograssBarDelegate
.add(ChecklistCellEditorEvent.newOption(text)); .add(ChecklistCellEditorEvent.newOption(text));
}, },
), ),
if (state.percent != 0)
Padding( Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0), padding: const EdgeInsets.only(top: 10.0),
child: ChecklistPrograssBar(percent: state.percent), child: ChecklistPrograssBar(percent: state.percent),
), ),
], ],
@ -88,6 +87,6 @@ class _SliverChecklistPrograssBarDelegate
@override @override
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) { bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
return false; return true;
} }
} }