fantascenza attachment bloc agnostico, ora continuo refactor rimuovendo customer file bloc ecc.
This commit is contained in:
@@ -7,7 +7,7 @@ import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flux/features/attachments/data/attachments_repository.dart';
|
||||
import 'package:flux/features/attachments/ui/attachment_viewer_screen.dart';
|
||||
import 'package:flux/features/attachments/ui/quick_rename_dialog.dart';
|
||||
import 'package:flux/features/attachments/blocs/operation_files_bloc.dart';
|
||||
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
@@ -88,16 +88,14 @@ class _OperationFilesSectionState extends State<OperationFilesSection> {
|
||||
|
||||
if (result != null && mounted) {
|
||||
// MAGIA: Passiamo direttamente la lista di PlatformFile al tuo BLoC!
|
||||
context.read<OperationFilesBloc>().add(
|
||||
AddOperationFilesEvent(result.files),
|
||||
);
|
||||
context.read<AttachmentsBloc>().add(AddAttachmentsEvent(result.files));
|
||||
}
|
||||
}
|
||||
|
||||
// --- APERTURA VIEWER ---
|
||||
void _openFile(AttachmentModel file) {
|
||||
// 1. Catturiamo il BLoC dalla pagina corrente prima di navigare
|
||||
final operationFilesBloc = context.read<OperationFilesBloc>();
|
||||
final operationFilesBloc = context.read<AttachmentsBloc>();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
@@ -107,10 +105,10 @@ class _OperationFilesSectionState extends State<OperationFilesSection> {
|
||||
attachment: file,
|
||||
onRename: (newName) {
|
||||
// Spara l'evento al BLoC e lui farà il resto!
|
||||
operationFilesBloc.add(RenameOperationFileEvent(file, newName));
|
||||
operationFilesBloc.add(RenameAttachmentEvent(file, newName));
|
||||
},
|
||||
onDelete: () {
|
||||
operationFilesBloc.add(DeleteSpecificOperationFileEvent(file));
|
||||
operationFilesBloc.add(DeleteSpecificAttachmentEvent(file));
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -392,7 +390,7 @@ class _OperationFilesSectionState extends State<OperationFilesSection> {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
// USIAMO IL TUO BLOC!
|
||||
return BlocBuilder<OperationFilesBloc, OperationFilesState>(
|
||||
return BlocBuilder<AttachmentsBloc, AttachmentsState>(
|
||||
builder: (context, state) {
|
||||
final allFiles = state.allFiles;
|
||||
final selectedFiles = state.selectedFiles;
|
||||
@@ -442,7 +440,7 @@ class _OperationFilesSectionState extends State<OperationFilesSection> {
|
||||
ElevatedButton.icon(
|
||||
icon: const Icon(Icons.add_photo_alternate),
|
||||
label: const Text('Aggiungi File'),
|
||||
onPressed: state.status == OperationFilesStatus.uploading
|
||||
onPressed: state.status == AttachmentsStatus.uploading
|
||||
? null
|
||||
: _pickFiles,
|
||||
),
|
||||
@@ -463,12 +461,12 @@ class _OperationFilesSectionState extends State<OperationFilesSection> {
|
||||
),
|
||||
onPressed: () {
|
||||
if (selectedFiles.length == allFiles.length) {
|
||||
context.read<OperationFilesBloc>().add(
|
||||
ClearOperationFileSelectionEvent(),
|
||||
context.read<AttachmentsBloc>().add(
|
||||
ClearAttachmentSelectionEvent(),
|
||||
);
|
||||
} else {
|
||||
context.read<OperationFilesBloc>().add(
|
||||
SelectAllOperationFilesEvent(),
|
||||
context.read<AttachmentsBloc>().add(
|
||||
SelectAllAttachmentsEvent(),
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -477,7 +475,7 @@ class _OperationFilesSectionState extends State<OperationFilesSection> {
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// Loader di upload
|
||||
if (state.status == OperationFilesStatus.uploading)
|
||||
if (state.status == AttachmentsStatus.uploading)
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
@@ -493,8 +491,8 @@ class _OperationFilesSectionState extends State<OperationFilesSection> {
|
||||
icon: const Icon(Icons.delete, color: Colors.red),
|
||||
tooltip: 'Elimina selezionati',
|
||||
onPressed: () {
|
||||
context.read<OperationFilesBloc>().add(
|
||||
DeleteOperationFilesEvent(),
|
||||
context.read<AttachmentsBloc>().add(
|
||||
DeleteAttachmentsEvent(),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -505,9 +503,10 @@ class _OperationFilesSectionState extends State<OperationFilesSection> {
|
||||
icon: const Icon(Icons.person_add, color: Colors.blue),
|
||||
tooltip: 'Copia nei documenti del Cliente',
|
||||
onPressed: () {
|
||||
context.read<OperationFilesBloc>().add(
|
||||
LinkFilesToCustomerEvent(
|
||||
customerId: widget.currentOp.customerId!,
|
||||
context.read<AttachmentsBloc>().add(
|
||||
LinkAttachmentsToEntityEvent(
|
||||
targetId: widget.currentOp.customerId!,
|
||||
targetType: AttachmentParentType.customer,
|
||||
),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -621,8 +620,8 @@ class _OperationFilesSectionState extends State<OperationFilesSection> {
|
||||
onTap: () => _openFile(file),
|
||||
onLongPress: () {
|
||||
// Selezione rapida con long press!
|
||||
context.read<OperationFilesBloc>().add(
|
||||
ToggleOperationFileSelectionEvent(file),
|
||||
context.read<AttachmentsBloc>().add(
|
||||
ToggleAttachmentSelectionEvent(file),
|
||||
);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
@@ -696,8 +695,8 @@ class _OperationFilesSectionState extends State<OperationFilesSection> {
|
||||
right: 4,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
context.read<OperationFilesBloc>().add(
|
||||
ToggleOperationFileSelectionEvent(file),
|
||||
context.read<AttachmentsBloc>().add(
|
||||
ToggleAttachmentSelectionEvent(file),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
|
||||
Reference in New Issue
Block a user