dialog qr si chiude quando upload finito

This commit is contained in:
2026-05-09 11:43:54 +02:00
parent 73c5751677
commit a81515e4d8
3 changed files with 18 additions and 19 deletions

View File

@@ -507,11 +507,16 @@ class _SharedAttachmentsSectionState extends State<SharedAttachmentsSection> {
'https://flux.catelli.it/upload/${state.parentType.name}/$targetId?companyId=$companyId'; 'https://flux.catelli.it/upload/${state.parentType.name}/$targetId?companyId=$companyId';
if (context.mounted) { if (context.mounted) {
final attachmentBloc = context.read<AttachmentsBloc>();
showDialog( showDialog(
context: context, context: context,
builder: (_) => QrUploadDialog( builder: (_) => BlocProvider.value(
deepLinkUrl: deepLink, value: attachmentBloc,
title: 'Carica File: ${widget.titleForUpload}', child: QrUploadDialog(
deepLinkUrl: deepLink,
title: 'Carica File: ${widget.titleForUpload}',
),
), ),
); );
} }

View File

@@ -82,7 +82,7 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
} }
} }
emit(state.copyWith(localFiles: [], status: AttachmentsStatus.success)); emit(state.copyWith(localFiles: [], status: AttachmentsStatus.ready));
add(LoadAttachmentsEvent(parentId: event.newParentId)); add(LoadAttachmentsEvent(parentId: event.newParentId));
} }
@@ -100,10 +100,8 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
currentId, currentId,
state.parentType, state.parentType,
), // Passiamo il tipo! ), // Passiamo il tipo!
onData: (List<AttachmentModel> data) => state.copyWith( onData: (List<AttachmentModel> data) =>
status: AttachmentsStatus.success, state.copyWith(status: AttachmentsStatus.ready, remoteFiles: data),
remoteFiles: data,
),
onError: (error, stackTrace) => state.copyWith( onError: (error, stackTrace) => state.copyWith(
status: AttachmentsStatus.failure, status: AttachmentsStatus.failure,
error: error.toString(), error: error.toString(),
@@ -143,7 +141,7 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
emit( emit(
state.copyWith( state.copyWith(
localFiles: [...state.localFiles, ...newLocalFiles], localFiles: [...state.localFiles, ...newLocalFiles],
status: AttachmentsStatus.success, status: AttachmentsStatus.ready,
), ),
); );
return; return;
@@ -162,7 +160,7 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
}).toList(); }).toList();
await Future.wait(uploadTasks); await Future.wait(uploadTasks);
emit(state.copyWith(status: AttachmentsStatus.success)); emit(state.copyWith(status: AttachmentsStatus.ready));
} catch (e) { } catch (e) {
emit( emit(
state.copyWith(status: AttachmentsStatus.failure, error: e.toString()), state.copyWith(status: AttachmentsStatus.failure, error: e.toString()),
@@ -245,9 +243,7 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
files: state.selectedFiles, files: state.selectedFiles,
currentContextType: state.parentType, currentContextType: state.parentType,
); );
emit( emit(state.copyWith(status: AttachmentsStatus.ready, selectedFiles: []));
state.copyWith(status: AttachmentsStatus.success, selectedFiles: []),
);
} catch (e) { } catch (e) {
emit( emit(
state.copyWith(status: AttachmentsStatus.failure, error: e.toString()), state.copyWith(status: AttachmentsStatus.failure, error: e.toString()),
@@ -311,7 +307,7 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
state.copyWith( state.copyWith(
localFiles: updatedLocalFiles, localFiles: updatedLocalFiles,
selectedFiles: [], // Svuotiamo la selezione selectedFiles: [], // Svuotiamo la selezione
status: AttachmentsStatus.success, status: AttachmentsStatus.ready,
), ),
); );
return; return;
@@ -337,9 +333,7 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
await Future.wait(linkTasks); await Future.wait(linkTasks);
// Lo stream aggiornerà automaticamente la UI // Lo stream aggiornerà automaticamente la UI
emit( emit(state.copyWith(status: AttachmentsStatus.ready, selectedFiles: []));
state.copyWith(status: AttachmentsStatus.success, selectedFiles: []),
);
} catch (e) { } catch (e) {
emit( emit(
state.copyWith( state.copyWith(
@@ -370,7 +364,7 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
emit(state.copyWith(status: AttachmentsStatus.loading)); emit(state.copyWith(status: AttachmentsStatus.loading));
try { try {
await _repository.renameAttachment(event.file.id!, event.newName); await _repository.renameAttachment(event.file.id!, event.newName);
emit(state.copyWith(status: AttachmentsStatus.success)); emit(state.copyWith(status: AttachmentsStatus.ready));
} catch (e) { } catch (e) {
emit( emit(
state.copyWith( state.copyWith(

View File

@@ -1,6 +1,6 @@
part of 'attachments_bloc.dart'; part of 'attachments_bloc.dart';
enum AttachmentsStatus { initial, loading, uploading, success, failure } enum AttachmentsStatus { initial, loading, ready, uploading, success, failure }
enum AttachmentParentType { enum AttachmentParentType {
operation('operation_id'), operation('operation_id'),