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

@@ -35,6 +35,7 @@ class DocumentUploadPage extends StatefulWidget {
final String? title;
final String? filename;
final void Function()? afterUpload;
final void Function(DocumentModel)? onSuccessfullyConsumed;
const DocumentUploadPage({
Key? key,
@@ -42,6 +43,7 @@ class DocumentUploadPage extends StatefulWidget {
this.afterUpload,
this.title,
this.filename,
this.onSuccessfullyConsumed,
}) : super(key: key);
@override
@@ -229,6 +231,7 @@ class _DocumentUploadPageState extends State<DocumentUploadPage> {
void _onSubmit() async {
if (_formKey.currentState?.saveAndValidate() ?? false) {
final cubit = BlocProvider.of<DocumentScannerCubit>(context);
try {
setState(() => _isUploadLoading = true);
@@ -240,17 +243,19 @@ class _DocumentUploadPageState extends State<DocumentUploadPage> {
final tags = fv[DocumentModel.tagsKey] as IdsTagsQuery;
final correspondent =
fv[DocumentModel.correspondentKey] as IdQueryParameter;
await BlocProvider.of<DocumentsCubit>(context).addDocument(
await cubit.uploadDocument(
widget.fileBytes,
_padWithPdfExtension(_formKey.currentState?.value[fkFileName]),
onConsumptionFinished: _onConsumptionFinished,
onConsumptionFinished: widget.onSuccessfullyConsumed,
title: title,
documentType: docType.id,
correspondent: correspondent.id,
tags: tags.ids,
createdAt: createdAt,
);
getIt<DocumentScannerCubit>().reset(); //TODO: Access via provider
cubit.reset(); //TODO: Access via provider
showSnackBar(context, S.of(context).documentUploadSuccessText);
Navigator.pop(context);
widget.afterUpload?.call();
@@ -275,24 +280,4 @@ class _DocumentUploadPageState extends State<DocumentUploadPage> {
String _formatFilename(String source) {
return source.replaceAll(RegExp(r"[\W_]"), "_");
}
void _onConsumptionFinished(DocumentModel document) {
// ScaffoldMessenger.of(rootScaffoldKey.currentContext!).showSnackBar(
// SnackBar(
// action: SnackBarAction(
// onPressed: () async {
// try {
// getIt<DocumentsCubit>().reloadDocuments();
// } on ErrorMessage catch (error, stackTrace) {
// showErrorMessage(context, error, stackTrace);
// }
// },
// label:
// S.of(context).documentUploadProcessingSuccessfulReloadActionText,
// ),
// content: Text(S.of(context).documentUploadProcessingSuccessfulText),
// ),
// );
getIt<PaperlessStatisticsCubit>().incrementInboxCount();
}
}