mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-08 04:07:51 -06:00
Started removing tight coupling
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user