Started removing tight coupling

This commit is contained in:
Anton Stubenbord
2022-11-24 22:51:42 +01:00
parent eb5025e8ca
commit 5edbdabf26
27 changed files with 845 additions and 693 deletions

View File

@@ -6,12 +6,16 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:paperless_mobile/core/model/error_message.dart';
import 'package:injectable/injectable.dart';
import 'package:paperless_mobile/features/documents/model/document.model.dart';
import 'package:paperless_mobile/features/documents/repository/document_repository.dart';
@singleton
@injectable
class DocumentScannerCubit extends Cubit<List<File>> {
final DocumentRepository documentRepository;
static List<File> initialState = [];
DocumentScannerCubit() : super(initialState);
DocumentScannerCubit(this.documentRepository) : super(initialState);
void addScan(File file) => emit([...state, file]);
@@ -40,4 +44,30 @@ class DocumentScannerCubit extends Cubit<List<File>> {
throw const ErrorMessage(ErrorCode.scanRemoveFailed);
}
}
Future<void> uploadDocument(
Uint8List bytes,
String fileName, {
required String title,
required void Function(DocumentModel document)? onConsumptionFinished,
int? documentType,
int? correspondent,
Iterable<int> tags = const [],
DateTime? createdAt,
}) async {
await documentRepository.create(
bytes,
fileName,
title: title,
documentType: documentType,
correspondent: correspondent,
tags: tags,
createdAt: createdAt,
);
if (onConsumptionFinished != null) {
documentRepository
.waitForConsumptionFinished(fileName, title)
.then((value) => onConsumptionFinished(value));
}
}
}