2import 'dart:developer';
5import 'package:flutter/services.dart';
6import 'package:open_file/open_file.dart';
7import 'package:path_provider/path_provider.dart';
8import 'package:pdf/pdf.dart';
9import 'package:pdf/widgets.dart' as pw;
11import '../../common/models/manifest_document.dart';
12import '../../constants/assets.dart';
13import '../../services/user_info_service.dart';
18 final pdf = pw.Document();
29 log(
'Error loading signature: $e');
34 final Uint8List logoData = logoBytes.buffer.asUint8List();
35 final pw.MemoryImage logoImage = pw.MemoryImage(logoData);
38 final PdfColor headerBlue = PdfColor.fromInt(0xFFB3D7EA);
40 final fontData = await rootBundle.load(
'assets/fonts/cairo_regular_font.ttf');
41 final ttf = pw.Font.ttf(fontData);
43 final theme = pw.ThemeData.withFont(
51 if (
date == null)
return '--';
52 return '${date.day}/${date.month}/${date.year}';
58 pageFormat: PdfPageFormat.a4,
59 margin:
const pw.EdgeInsets.all(20),
60 build: (context) => pw.Column(
61 crossAxisAlignment: pw.CrossAxisAlignment.start,
65 mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
67 pw.Image(logoImage, width: 80, height: 80),
69 crossAxisAlignment: pw.CrossAxisAlignment.center,
72 'Waste Electronic Manifest',
75 fontWeight: pw.FontWeight.bold,
82 fontWeight: pw.FontWeight.bold,
88 crossAxisAlignment: pw.CrossAxisAlignment.end,
92 pw.Text(
'Document No: ',
93 style: pw.TextStyle(fontSize: 10)),
94 pw.Text(
'${manifest.id}',
96 pw.TextStyle(fontSize: 10,
color: PdfColors.red)),
103 pw.SizedBox(height: 5),
107 child: pw.BarcodeWidget(
108 barcode: pw.Barcode.qrCode(),
110 'WASTE E-MANIFEST - Document No: ${manifest.id} - origin: Aidra Connect',
117 pw.SizedBox(height: 20),
121 width:
double.infinity,
123 padding:
const pw.EdgeInsets.symmetric(vertical: 5, horizontal: 10),
125 'Part - A : Waste Generator Information',
128 fontWeight: pw.FontWeight.bold,
134 _buildGeneratorInfoTable(manifest),
138 padding:
const pw.EdgeInsets.symmetric(horizontal: 10, vertical: 5),
140 crossAxisAlignment: pw.CrossAxisAlignment.start,
143 '4. Transporter\'s Name :',
145 fontSize: 10, fontWeight: pw.FontWeight.bold),
147 pw.SizedBox(height: 3),
149 padding:
const pw.EdgeInsets.only(left: 20),
151 crossAxisAlignment: pw.CrossAxisAlignment.start,
155 style: pw.TextStyle(fontSize: 10),
157 pw.SizedBox(height: 3),
163 style: pw.TextStyle(fontSize: 10),
168 'Person to Contact:',
169 style: pw.TextStyle(fontSize: 10),
182 pw.SizedBox(height: 10),
183 _buildShippingTable(manifest),
184 pw.SizedBox(height: 15),
188 padding:
const pw.EdgeInsets.symmetric(horizontal: 10, vertical: 5),
190 crossAxisAlignment: pw.CrossAxisAlignment.start,
193 '10. Generator\'s Certification: I hereby declare that the containers of this consignment are fully',
194 style: pw.TextStyle(fontSize: 10),
197 'and accurately described above by proper shipping name and classified, packed, and labelled,',
198 style: pw.TextStyle(fontSize: 10),
201 'and are in all respect in proper condition for transport by highway according to applicable laws',
202 style: pw.TextStyle(fontSize: 10),
205 'and regulations of the kingdom.',
206 style: pw.TextStyle(fontSize: 10),
208 pw.SizedBox(height: 15),
210 mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
213 'Name of the Authorized Representative :',
214 style: pw.TextStyle(fontSize: 10),
217 padding:
const pw.EdgeInsets.only(right: 50),
219 'Date: ${formatDate(manifest.collectionDate)}',
220 style: pw.TextStyle(fontSize: 9)),
224 pw.SizedBox(height: 8),
227 style: pw.TextStyle(fontSize: 10),
236 alignment: pw.Alignment.bottomRight,
238 crossAxisAlignment: pw.CrossAxisAlignment.end,
242 style: pw.TextStyle(fontSize: 8,
color: PdfColors.grey),
246 style: pw.TextStyle(fontSize: 8,
color: PdfColors.grey),
260 pageFormat: PdfPageFormat.a4,
261 margin:
const pw.EdgeInsets.all(20),
262 build: (context) => pw.Column(
263 crossAxisAlignment: pw.CrossAxisAlignment.start,
267 mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
269 pw.Image(logoImage, width: 80, height: 80),
271 crossAxisAlignment: pw.CrossAxisAlignment.center,
274 'Waste Electronic Manifest',
277 fontWeight: pw.FontWeight.bold,
284 fontWeight: pw.FontWeight.bold,
290 crossAxisAlignment: pw.CrossAxisAlignment.end,
294 pw.Text(
'Document No. ',
295 style: pw.TextStyle(fontSize: 10)),
296 pw.Text(
'${manifest.id}',
298 pw.TextStyle(fontSize: 10,
color: PdfColors.red)),
305 pw.SizedBox(height: 5),
309 child: pw.BarcodeWidget(
310 barcode: pw.Barcode.qrCode(),
313 'WASTE E-MANIFEST - Document No: ${manifest.id} - origin: Aidra Drive',
320 pw.SizedBox(height: 20),
324 width:
double.infinity,
326 padding:
const pw.EdgeInsets.symmetric(vertical: 5, horizontal: 10),
328 'Part - B : Transporter Informations',
331 fontWeight: pw.FontWeight.bold,
338 padding:
const pw.EdgeInsets.all(10),
340 crossAxisAlignment: pw.CrossAxisAlignment.start,
343 mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
346 '11. Transporter\'s Acknowledgment of Receipt of Materials',
347 style: pw.TextStyle(fontSize: 10),
350 'Date: ${formatDate(manifest.unloadingDate)}',
351 style: pw.TextStyle(fontSize: 10),
355 pw.SizedBox(height: 20),
357 mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
360 'Driver Name: ${manifest.driver?.name ?? ''}',
361 style: pw.TextStyle(fontSize: 10),
364 'Vehicle Plate No. ${manifest.vehiclePlate ?? ''}',
365 style: pw.TextStyle(fontSize: 10),
369 pw.SizedBox(height: 15),
371 'Signature of Drive:',
372 style: pw.TextStyle(fontSize: 10),
374 pw.SizedBox(height: 5),
384 decoration: pw.BoxDecoration(
386 bottom: pw.BorderSide(
color: PdfColors.black),
394 pw.SizedBox(height: 20),
398 width:
double.infinity,
400 padding:
const pw.EdgeInsets.symmetric(vertical: 5, horizontal: 10),
402 'Part - C : Warehouse Facility Information',
405 fontWeight: pw.FontWeight.bold,
412 padding:
const pw.EdgeInsets.all(10),
414 crossAxisAlignment: pw.CrossAxisAlignment.start,
417 '12. Discrepancy Indication Space',
418 style: pw.TextStyle(fontSize: 10),
420 pw.SizedBox(height: 20),
422 '13. Facility Owner/Operator: certification of material covered by',
423 style: pw.TextStyle(fontSize: 10),
426 'this manifest except as noted in item',
427 style: pw.TextStyle(fontSize: 10),
429 pw.SizedBox(height: 20),
431 mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
435 style: pw.TextStyle(fontSize: 10),
439 style: pw.TextStyle(fontSize: 10),
443 pw.SizedBox(height: 15),
446 style: pw.TextStyle(fontSize: 10),
455 alignment: pw.Alignment.bottomRight,
457 crossAxisAlignment: pw.CrossAxisAlignment.end,
461 style: pw.TextStyle(fontSize: 8,
color: PdfColors.grey),
465 style: pw.TextStyle(fontSize: 8,
color: PdfColors.grey),
475 final output = await getTemporaryDirectory();
476 final file = File(
'${output.path}/e_manifest.pdf');
477 await file.writeAsBytes(await pdf.save());
479 OpenFile.open(file.path);
485 border: pw.TableBorder.all(
color: PdfColors.black),
487 0: const pw.FlexColumnWidth(1),
488 1: const pw.FlexColumnWidth(1),
489 2: const pw.FlexColumnWidth(1),
496 padding:
const pw.EdgeInsets.all(5),
498 '1.Generator ID. No',
499 style: pw.TextStyle(fontSize: 10),
503 padding:
const pw.EdgeInsets.all(5),
505 '2. Generator\'S Name',
506 style: pw.TextStyle(fontSize: 10),
510 padding:
const pw.EdgeInsets.all(5),
512 '3. Generator\'s Address, Phone No. and Person To Contact',
513 style: pw.TextStyle(fontSize: 10),
519 ...manifest.collectionVoucher!.map((voucher) => pw.TableRow(
522 padding:
const pw.EdgeInsets.all(5),
524 voucher.id.toString(),
525 style: pw.TextStyle(fontSize: 10),
529 padding:
const pw.EdgeInsets.all(5),
531 voucher.collectionPoint ??
'',
532 style: pw.TextStyle(fontSize: 10),
536 padding:
const pw.EdgeInsets.all(5),
538 voucher.address ??
'',
539 style: pw.TextStyle(fontSize: 10),
551 border: pw.TableBorder.all(
color: PdfColors.black),
553 0: const pw.FlexColumnWidth(3),
554 1: const pw.FlexColumnWidth(2),
555 2: const pw.FlexColumnWidth(1),
556 3: const pw.FlexColumnWidth(1),
557 4: const pw.FlexColumnWidth(1),
562 decoration: pw.BoxDecoration(
color: PdfColors.blue50),
565 padding:
const pw.EdgeInsets.all(5),
567 '5.(Shipping Name, Hazard Class, and Pin)',
568 style: pw.TextStyle(fontSize: 9),
574 width:
double.infinity,
575 alignment: pw.Alignment.center,
576 padding:
const pw.EdgeInsets.all(5),
579 style: pw.TextStyle(fontSize: 9),
583 border: pw.TableBorder(
584 top: pw.BorderSide(
color: PdfColors.black),
585 horizontalInside: pw.BorderSide(
color: PdfColors.black),
586 verticalInside: pw.BorderSide(
color: PdfColors.black),
589 0: const pw.FlexColumnWidth(1),
590 1: const pw.FlexColumnWidth(1),
596 alignment: pw.Alignment.center,
597 padding:
const pw.EdgeInsets.all(2),
598 child: pw.Text(
'No.', style: pw.TextStyle(fontSize: 8)),
601 alignment: pw.Alignment.center,
602 padding:
const pw.EdgeInsets.all(2),
604 pw.Text(
'Type', style: pw.TextStyle(fontSize: 8)),
613 alignment: pw.Alignment.center,
614 padding:
const pw.EdgeInsets.all(5),
617 style: pw.TextStyle(fontSize: 9),
621 alignment: pw.Alignment.center,
622 padding:
const pw.EdgeInsets.all(5),
625 style: pw.TextStyle(fontSize: 9),
629 alignment: pw.Alignment.center,
630 padding:
const pw.EdgeInsets.all(5),
633 style: pw.TextStyle(fontSize: 9),
643 padding: pw.EdgeInsets.only(left: 10),
648 border: pw.TableBorder(
649 verticalInside: pw.BorderSide(
color: PdfColors.black),
652 0: const pw.FlexColumnWidth(1),
653 1: const pw.FlexColumnWidth(1),
660 padding: pw.EdgeInsets.only(left: 10),
661 child: pw.Text(
'${manifest.containerNumber}')),
663 padding: pw.EdgeInsets.only(left: 10),
665 child: pw.Text(
'${manifest.containerType}')),
671 padding: pw.EdgeInsets.only(left: 10),
673 child: pw.Text(
'${manifest.totalQuantity ?? ''}')),
675 padding: pw.EdgeInsets.only(left: 10),
681 padding: pw.EdgeInsets.only(left: 10),
class App extends StatefulWidget build(BuildContext context)
static const String tajmielogo
final LocalizedString productName
static final UserInfoService instance
Future generateManifest(ManifestDocument manifest,) async