diff --git a/lib/features/document_scan/view/scanner_page.dart b/lib/features/document_scan/view/scanner_page.dart index 1d405d9..0d80406 100644 --- a/lib/features/document_scan/view/scanner_page.dart +++ b/lib/features/document_scan/view/scanner_page.dart @@ -208,7 +208,7 @@ class _ScannerPageState extends State final file = await _assembleFileBytes( context.read().state, ); - final taskId = await Navigator.of(context).push( + final uploadResult = await Navigator.of(context).push( MaterialPageRoute( builder: (_) => LabelRepositoriesProvider( child: BlocProvider( @@ -228,10 +228,12 @@ class _ScannerPageState extends State ), ), ); - if (taskId != null) { + if ((uploadResult?.success ?? false) && uploadResult?.taskId != null) { // For paperless version older than 1.11.3, task id will always be null! context.read().reset(); - context.read().listenToTaskChanges(taskId); + context + .read() + .listenToTaskChanges(uploadResult!.taskId!); } } diff --git a/lib/features/document_upload/view/document_upload_preparation_page.dart b/lib/features/document_upload/view/document_upload_preparation_page.dart index 6d28db3..ca44d33 100644 --- a/lib/features/document_upload/view/document_upload_preparation_page.dart +++ b/lib/features/document_upload/view/document_upload_preparation_page.dart @@ -19,6 +19,13 @@ import 'package:paperless_mobile/generated/l10n/app_localizations.dart'; import 'package:paperless_mobile/helpers/message_helpers.dart'; +class DocumentUploadResult { + final bool success; + final String? taskId; + + DocumentUploadResult(this.success, this.taskId); +} + class DocumentUploadPreparationPage extends StatefulWidget { final Uint8List fileBytes; final String? title; @@ -259,13 +266,19 @@ class _DocumentUploadPreparationPageState createdAt: createdAt, ); showSnackBar( - context, S.of(context)!.documentSuccessfullyUploadedProcessing); - Navigator.pop(context, taskId); + context, + S.of(context)!.documentSuccessfullyUploadedProcessing, + ); + Navigator.pop( + context, + DocumentUploadResult(true, taskId), + ); } on PaperlessServerException catch (error, stackTrace) { showErrorMessage(context, error, stackTrace); } on PaperlessValidationErrors catch (errors) { setState(() => _errors = errors); } catch (unknownError, stackTrace) { + debugPrint(unknownError.toString()); showErrorMessage( context, const PaperlessServerException.unknown(), stackTrace); } finally { diff --git a/lib/features/home/view/home_page.dart b/lib/features/home/view/home_page.dart index dc6f7cb..aa4bb53 100644 --- a/lib/features/home/view/home_page.dart +++ b/lib/features/home/view/home_page.dart @@ -156,27 +156,26 @@ class _HomePageState extends State with WidgetsBindingObserver { final extension = p.extension(mediaFile.path); if (await File(mediaFile.path).exists()) { final bytes = File(mediaFile.path).readAsBytesSync(); - final success = await Navigator.push( - context, - MaterialPageRoute( - builder: (context) => BlocProvider.value( - value: DocumentUploadCubit( - documentApi: context.read(), - tagRepository: context.read(), - correspondentRepository: context.read(), - documentTypeRepository: context.read(), - ), - child: DocumentUploadPreparationPage( - fileBytes: bytes, - filename: filename, - title: filename, - fileExtension: extension, - ), - ), + final result = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => BlocProvider.value( + value: DocumentUploadCubit( + documentApi: context.read(), + tagRepository: context.read(), + correspondentRepository: context.read(), + documentTypeRepository: context.read(), ), - ) ?? - false; - if (success) { + child: DocumentUploadPreparationPage( + fileBytes: bytes, + filename: filename, + title: filename, + fileExtension: extension, + ), + ), + ), + ); + if (result?.success ?? false) { await Fluttertoast.showToast( msg: S.of(context)!.documentSuccessfullyUploadedProcessing, );