Changed saved views handling, changed repository structure with automatic persistence.

This commit is contained in:
Anton Stubenbord
2023-01-08 00:01:04 +01:00
parent 23bcb355b1
commit 3c6c4e63d7
74 changed files with 1374 additions and 863 deletions

View File

@@ -3,25 +3,26 @@ import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/repository/label_repository.dart';
import 'package:paperless_mobile/core/repository/state/repository_state.dart';
import 'package:paperless_mobile/features/labels/bloc/label_state.dart';
class LabelCubit<T extends Label> extends Cubit<LabelState<T>> {
final LabelRepository<T> _repository;
final LabelRepository<T, RepositoryState> _repository;
late StreamSubscription _subscription;
LabelCubit(LabelRepository<T> repository)
LabelCubit(LabelRepository<T, RepositoryState> repository)
: _repository = repository,
super(LabelState(
isLoaded: repository.isInitialized,
labels: repository.current ?? {},
labels: repository.current?.values ?? {},
)) {
_subscription = _repository.values.listen(
(update) {
if (update == null) {
(event) {
if (event == null) {
emit(LabelState());
}
emit(LabelState(isLoaded: true, labels: update!));
emit(LabelState(isLoaded: true, labels: event!.values));
},
);
}