From a81515e4d87eebb98e0bcadaccf004e581d7ae30 Mon Sep 17 00:00:00 2001 From: Mark M2 Macbook Date: Sat, 9 May 2026 11:43:54 +0200 Subject: [PATCH] dialog qr si chiude quando upload finito --- .../shared_forms/attachments_section.dart | 11 ++++++--- .../attachments/blocs/attachments_bloc.dart | 24 +++++++------------ .../attachments/blocs/attachments_state.dart | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/core/widgets/shared_forms/attachments_section.dart b/lib/core/widgets/shared_forms/attachments_section.dart index af7ec31..b2fa64f 100644 --- a/lib/core/widgets/shared_forms/attachments_section.dart +++ b/lib/core/widgets/shared_forms/attachments_section.dart @@ -507,11 +507,16 @@ class _SharedAttachmentsSectionState extends State { 'https://flux.catelli.it/upload/${state.parentType.name}/$targetId?companyId=$companyId'; if (context.mounted) { + final attachmentBloc = context.read(); + showDialog( context: context, - builder: (_) => QrUploadDialog( - deepLinkUrl: deepLink, - title: 'Carica File: ${widget.titleForUpload}', + builder: (_) => BlocProvider.value( + value: attachmentBloc, + child: QrUploadDialog( + deepLinkUrl: deepLink, + title: 'Carica File: ${widget.titleForUpload}', + ), ), ); } diff --git a/lib/features/attachments/blocs/attachments_bloc.dart b/lib/features/attachments/blocs/attachments_bloc.dart index fb60323..80935fb 100644 --- a/lib/features/attachments/blocs/attachments_bloc.dart +++ b/lib/features/attachments/blocs/attachments_bloc.dart @@ -82,7 +82,7 @@ class AttachmentsBloc extends Bloc { } } - emit(state.copyWith(localFiles: [], status: AttachmentsStatus.success)); + emit(state.copyWith(localFiles: [], status: AttachmentsStatus.ready)); add(LoadAttachmentsEvent(parentId: event.newParentId)); } @@ -100,10 +100,8 @@ class AttachmentsBloc extends Bloc { currentId, state.parentType, ), // Passiamo il tipo! - onData: (List data) => state.copyWith( - status: AttachmentsStatus.success, - remoteFiles: data, - ), + onData: (List data) => + state.copyWith(status: AttachmentsStatus.ready, remoteFiles: data), onError: (error, stackTrace) => state.copyWith( status: AttachmentsStatus.failure, error: error.toString(), @@ -143,7 +141,7 @@ class AttachmentsBloc extends Bloc { emit( state.copyWith( localFiles: [...state.localFiles, ...newLocalFiles], - status: AttachmentsStatus.success, + status: AttachmentsStatus.ready, ), ); return; @@ -162,7 +160,7 @@ class AttachmentsBloc extends Bloc { }).toList(); await Future.wait(uploadTasks); - emit(state.copyWith(status: AttachmentsStatus.success)); + emit(state.copyWith(status: AttachmentsStatus.ready)); } catch (e) { emit( state.copyWith(status: AttachmentsStatus.failure, error: e.toString()), @@ -245,9 +243,7 @@ class AttachmentsBloc extends Bloc { files: state.selectedFiles, currentContextType: state.parentType, ); - emit( - state.copyWith(status: AttachmentsStatus.success, selectedFiles: []), - ); + emit(state.copyWith(status: AttachmentsStatus.ready, selectedFiles: [])); } catch (e) { emit( state.copyWith(status: AttachmentsStatus.failure, error: e.toString()), @@ -311,7 +307,7 @@ class AttachmentsBloc extends Bloc { state.copyWith( localFiles: updatedLocalFiles, selectedFiles: [], // Svuotiamo la selezione - status: AttachmentsStatus.success, + status: AttachmentsStatus.ready, ), ); return; @@ -337,9 +333,7 @@ class AttachmentsBloc extends Bloc { await Future.wait(linkTasks); // Lo stream aggiornerĂ  automaticamente la UI - emit( - state.copyWith(status: AttachmentsStatus.success, selectedFiles: []), - ); + emit(state.copyWith(status: AttachmentsStatus.ready, selectedFiles: [])); } catch (e) { emit( state.copyWith( @@ -370,7 +364,7 @@ class AttachmentsBloc extends Bloc { emit(state.copyWith(status: AttachmentsStatus.loading)); try { await _repository.renameAttachment(event.file.id!, event.newName); - emit(state.copyWith(status: AttachmentsStatus.success)); + emit(state.copyWith(status: AttachmentsStatus.ready)); } catch (e) { emit( state.copyWith( diff --git a/lib/features/attachments/blocs/attachments_state.dart b/lib/features/attachments/blocs/attachments_state.dart index 827db86..ae99107 100644 --- a/lib/features/attachments/blocs/attachments_state.dart +++ b/lib/features/attachments/blocs/attachments_state.dart @@ -1,6 +1,6 @@ part of 'attachments_bloc.dart'; -enum AttachmentsStatus { initial, loading, uploading, success, failure } +enum AttachmentsStatus { initial, loading, ready, uploading, success, failure } enum AttachmentParentType { operation('operation_id'),