WIP - more decoupling of blocs

This commit is contained in:
Anton Stubenbord
2022-12-12 01:29:34 +01:00
parent e2a20cea75
commit 2f31d9c053
51 changed files with 1083 additions and 800 deletions

View File

@@ -11,9 +11,13 @@ class LabelCubit<T extends Label> extends Cubit<LabelState<T>> {
late StreamSubscription _subscription;
LabelCubit(this._repository) : super(LabelState.initial()) {
LabelCubit(LabelRepository<T> repository)
: _repository = repository,
super(LabelState(labels: repository.current, isLoaded: true)) {
_subscription = _repository.labels.listen(
(update) => emit(LabelState(isLoaded: true, labels: update)),
(update) => emit(
LabelState(isLoaded: true, labels: update),
),
);
}
@@ -28,6 +32,10 @@ class LabelCubit<T extends Label> extends Cubit<LabelState<T>> {
return addedItem;
}
Future<void> reload() {
return _repository.findAll();
}
Future<T> replace(T item) async {
assert(item.id != null);
final updatedItem = await _repository.update(item);