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

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

View File

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

View File

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