refactor shipping attachments and changed shipment to shipping for coherence

This commit is contained in:
2026-05-18 12:00:07 +02:00
parent b06a655bc3
commit 5e99324201
15 changed files with 359 additions and 152 deletions

View File

@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flux/core/routes/routes.dart';
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
import 'package:flux/features/attachments/models/attachment_model.dart';
import 'package:flux/features/attachments/ui/attachment_viewer_screen.dart';
import 'package:flux/features/tickets/blocs/ticket_list_cubit.dart';
import 'package:flux/features/tickets/models/ticket_model.dart';
import 'package:flux/features/tickets/models/ticket_status_extension.dart';
@@ -20,6 +23,32 @@ class TicketListCard extends StatelessWidget {
required this.isDesktop,
});
void _openFile({
required BuildContext context,
required AttachmentModel file,
}) {
// 1. Catturiamo il BLoC dalla pagina corrente prima di navigare
final operationFilesBloc = context.read<AttachmentsBloc>();
Navigator.push(
context,
MaterialPageRoute(
builder: (viewerContext) => BlocProvider.value(
value: operationFilesBloc,
child: AttachmentViewerScreen(
attachment: file,
onRename: (newName) {
// Spara l'evento al BLoC e lui farà il resto!
operationFilesBloc.add(RenameAttachmentEvent(file, newName));
},
onDelete: () {
operationFilesBloc.add(DeleteSpecificAttachmentEvent(file));
},
),
),
),
);
}
@override
Widget build(BuildContext context) {
final statusColor = ticket.ticketStatus.color;
@@ -110,21 +139,57 @@ class TicketListCard extends StatelessWidget {
overflow: TextOverflow.ellipsis,
),
),
if (ticket.shippingDocument != null) ...[
Row(
children: [
const Text('DDT'),
const SizedBox(width: 4),
InkWell(
borderRadius: BorderRadius.circular(20),
onTap: () {},
child: const Icon(
Icons.picture_as_pdf,
color: Colors.redAccent,
size: 20,
),
),
],
if (ticket.shippingDocument != null &&
ticket.shippingDocument!.attachments.isNotEmpty) ...[
IconButton(
icon: const Icon(
Icons.picture_as_pdf,
color: Colors.redAccent,
),
onPressed: () {
final attachments =
ticket.shippingDocument!.attachments;
if (attachments.length == 1) {
// CASO 1: C'è solo il DDT. Apriamo SUBITO il Document Viewer!
_openFile(
context: context,
file: attachments.first,
);
} else {
// CASO 2: Più allegati. Mostriamo una BottomSheet fulminea per far scegliere all'utente.
showModalBottomSheet(
context: context,
builder: (context) => ListView.builder(
shrinkWrap: true,
itemCount: attachments.length,
itemBuilder: (context, index) {
final file = attachments[index];
return ListTile(
leading: Icon(
file.extension == 'pdf'
? Icons.picture_as_pdf
: Icons.image,
),
title: Text(file.name),
subtitle: Text(
'${(file.fileSize / 1024).toStringAsFixed(1)} KB',
),
onTap: () {
Navigator.pop(
context,
); // Chiude la scelta
_openFile(
context: context,
file: file,
); // Apre il viewer
},
);
},
),
);
}
},
),
],