df
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
@@ -7,6 +10,7 @@ import 'package:flux/features/master_data/providers/models/provider_model.dart';
|
||||
import 'package:flux/features/tickets/blocs/ticket_list_cubit.dart';
|
||||
import 'package:flux/features/tickets/blocs/ticket_list_state.dart';
|
||||
import 'package:flux/features/tickets/blocs/ticket_shipping_cubit.dart';
|
||||
import 'package:flux/features/tickets/models/ticket_model.dart';
|
||||
import 'package:flux/features/tickets/ui/widgets/ticket_list_card.dart';
|
||||
import 'package:flux/features/tickets/ui/widgets/ticket_shipping_modal.dart';
|
||||
import 'package:flux/features/tickets/utils/ticket_shipping_pdf_service.dart';
|
||||
@@ -99,22 +103,14 @@ class TicketList extends StatelessWidget {
|
||||
FilledButton.icon(
|
||||
onPressed: () async {
|
||||
// 1. Apriamo la modale e ASPETTIAMO il risultato (tipizzandolo come Record)
|
||||
final result =
|
||||
await showModalBottomSheet<
|
||||
({
|
||||
ShipmentDocumentModel document,
|
||||
ProviderModel provider,
|
||||
ProviderLocationModel location,
|
||||
})
|
||||
>(
|
||||
final Uint8List? result =
|
||||
await showModalBottomSheet<Uint8List>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (context) {
|
||||
return BlocProvider(
|
||||
create: (context) => TicketShippingCubit(
|
||||
ticketIds: state.selectedTickets
|
||||
.map((t) => t.id!)
|
||||
.toList(),
|
||||
tickets: state.selectedTickets.toList(),
|
||||
)..loadRepairCenters(),
|
||||
child: TicketShippingModal(
|
||||
ticketIds: state.selectedTickets
|
||||
@@ -128,41 +124,17 @@ class TicketList extends StatelessWidget {
|
||||
// 2. Se l'utente ha chiuso trascinando giù, result è null.
|
||||
// Se ha salvato con successo, result contiene il nostro Record!
|
||||
if (result != null && context.mounted) {
|
||||
try {
|
||||
// Recuperiamo la Company (dal tuo SessionCubit o AuthCubit)
|
||||
final company = context
|
||||
.read<SessionCubit>()
|
||||
.state
|
||||
.company!;
|
||||
|
||||
final ticketListCubit = context
|
||||
.read<TicketListCubit>();
|
||||
|
||||
// 3. GENERIAMO I BYTES DEL PDF
|
||||
final pdfBytes =
|
||||
await TicketShippingPdfService.generateDdt(
|
||||
company: company,
|
||||
provider: result.provider,
|
||||
location: result.location,
|
||||
document: result.document,
|
||||
tickets: state.selectedTickets.toList(),
|
||||
);
|
||||
await Printing.layoutPdf(
|
||||
onLayout: (PdfPageFormat format) async => pdfBytes,
|
||||
name: 'ddt_${result.document.docNumber}.pdf',
|
||||
);
|
||||
|
||||
// 5. Pulizia finale: Deselezioniamo tutti i ticket e ricarichiamo la lista
|
||||
ticketListCubit.clearSelection();
|
||||
// (Se necessario, chiama il metodo per ricaricare la lista dei ticket dal DB)
|
||||
ticketListCubit.loadTickets(refresh: true);
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Errore stampa PDF: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
await Printing.layoutPdf(
|
||||
onLayout: (format) async => result,
|
||||
name:
|
||||
'DDT_${DateTime.now().millisecondsSinceEpoch}.pdf',
|
||||
);
|
||||
// 5. Pulizia finale: Deselezioniamo tutti i ticket e ricarichiamo la lista
|
||||
context.read<TicketListCubit>().clearSelection();
|
||||
// (Se necessario, chiama il metodo per ricaricare la lista dei ticket dal DB)
|
||||
context.read<TicketListCubit>().loadTickets(
|
||||
refresh: true,
|
||||
);
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.local_shipping),
|
||||
|
||||
Reference in New Issue
Block a user