fix mobile upload

This commit is contained in:
2026-05-09 09:50:20 +02:00
parent c6ef798b22
commit 65aa3c7de8
11 changed files with 164 additions and 52 deletions

View File

@@ -14,6 +14,7 @@ part 'attachments_state.dart';
class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
final _repository = GetIt.I.get<AttachmentsRepository>();
final String? companyId = GetIt.I.get<SessionCubit>().state.company?.id;
AttachmentsBloc({String? parentId, required AttachmentParentType parentType})
: super(
@@ -36,7 +37,7 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
on<ClearAttachmentSelectionEvent>(_onClearAttachmentSelection);
// Se il BLoC nasce già con un ID, carichiamo i file
if (parentId != null) {
if (parentId != null && companyId != null) {
add(LoadAttachmentsEvent(parentId: parentId));
}
}
@@ -65,6 +66,7 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
parentId: event.newParentId,
parentType: state.parentType,
pickedFile: fakePlatformFile,
companyId: companyId!,
);
}).toList();
@@ -118,12 +120,11 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
// BIVIO 1: PRATICA NUOVA (Salvataggio locale)
if (currentId == null) {
final companyId = GetIt.I.get<SessionCubit>().state.company!.id!;
final newLocalFiles = event.files.map((file) {
// Assegniamo i campi dinamicamente in base al parentType!
return AttachmentModel(
id: null,
companyId: companyId,
companyId: companyId!,
operationId: state.parentType == AttachmentParentType.operation
? ''
: null,
@@ -156,6 +157,7 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
parentId: currentId,
parentType: state.parentType,
pickedFile: file,
companyId: companyId!,
);
}).toList();
@@ -191,6 +193,7 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
parentId: state.parentId!,
parentType: state.parentType,
pickedFile: file,
companyId: event.companyId,
),
);
}
@@ -216,6 +219,7 @@ class AttachmentsBloc extends Bloc<AttachmentsEvent, AttachmentsState> {
parentId: state.parentId!,
parentType: state.parentType,
pickedFile: fakePlatformFile,
companyId: companyId!,
),
);
}

View File

@@ -29,7 +29,12 @@ class AddAttachmentsEvent extends AttachmentsEvent {
class UploadAttachmentsEvent extends AttachmentsEvent {
final List<PlatformFile>? pickedFiles;
final List<XFile>? photos;
const UploadAttachmentsEvent({this.pickedFiles, this.photos});
final String companyId;
const UploadAttachmentsEvent({
this.pickedFiles,
this.photos,
required this.companyId,
});
}
class DeleteAttachmentsEvent extends AttachmentsEvent {}

View File

@@ -16,6 +16,7 @@ class AttachmentsState extends Equatable {
final AttachmentParentType parentType;
final AttachmentsStatus status;
final String? error;
final List<AttachmentModel> localFiles;
final List<AttachmentModel> remoteFiles;
final List<AttachmentModel> selectedFiles;