1import 'dart:developer';
4import 'package:flutter/services.dart';
5import 'package:flutter_screenutil/flutter_screenutil.dart';
6import 'package:open_file/open_file.dart';
7import 'package:pdf/pdf.dart';
8import 'package:pdf/widgets.dart' as pw;
9import 'package:path_provider/path_provider.dart';
11import '../../constants/assets.dart';
12import '../../services/user_info_service.dart';
13import '../../common/models/collection_voucher_document_model.dart';
16 final pdf = pw.Document();
18 final font = await rootBundle.load(
'assets/fonts/cairo_regular_font.ttf');
19 final ttf = pw.Font.ttf(font);
21 final theme = pw.ThemeData.withFont(
31 log(
'Error decoding signature: $e');
35 final qrCode = pw.BarcodeWidget(
36 barcode: pw.Barcode.qrCode(),
37 data: model.collection.name ??
'',
42 final directorSignature = pw.Column(
45 'Driver / Collector : ${UserInfoService.instance.userInfo?.name ?? '--
'}',
46 style: pw.TextStyle(fontSize: 10, fontWeight: pw.FontWeight.bold),
55 fit: pw.BoxFit.contain,
62 final collectorSignature = pw.Column(
65 'Collection Point : ${model.collection.partnerId?.name ?? 'Shah waqar
'}',
66 style: pw.TextStyle(fontSize: 10, fontWeight: pw.FontWeight.bold),
76 fit: pw.BoxFit.contain,
85 textDirection: pw.TextDirection.ltr,
89 crossAxisAlignment: pw.CrossAxisAlignment.center,
93 style: pw.TextStyle(fontSize: 20, fontWeight: pw.FontWeight.bold),
95 pw.SizedBox(height: 8),
97 'Document Number : ${model.collection.name ?? ''}',
100 fontWeight: pw.FontWeight.normal,
101 color: PdfColor.fromHex(
'#1402a3'),
104 pw.SizedBox(height: 25),
106 alignment: pw.Alignment.centerLeft,
108 crossAxisAlignment: pw.CrossAxisAlignment.start,
113 style: pw.TextStyle(fontSize: 15, fontWeight: pw.FontWeight.bold),
116 model.collection.partnerId?.name ??
'',
118 fontSize: 14, fontWeight: pw.FontWeight.normal),
120 pw.SizedBox(height: 8),
123 style: pw.TextStyle(fontSize: 15, fontWeight: pw.FontWeight.bold),
126 model.collection.partnerId?.street ??
'',
127 textDirection: pw.TextDirection.rtl,
129 fontSize: 14, fontWeight: pw.FontWeight.normal,
136 pw.SizedBox(height: 30),
138 border: pw.TableBorder.all(),
143 padding: const pw.EdgeInsets.all(8),
146 style: pw.TextStyle(fontWeight: pw.FontWeight.bold),
150 padding: const pw.EdgeInsets.all(8),
151 child: pw.Text(model.collection.confirmationDate?.split(
'T')[0] ??
'--'),
154 padding: const pw.EdgeInsets.all(8),
157 style: pw.TextStyle(fontWeight: pw.FontWeight.bold),
161 padding: const pw.EdgeInsets.all(8),
162 child: pw.Text(model.collection.paymentBillRef ??
'--'),
169 padding: const pw.EdgeInsets.all(8),
171 'Collection Order Ref',
172 style: pw.TextStyle(fontWeight: pw.FontWeight.bold),
176 padding: const pw.EdgeInsets.all(8),
177 child: pw.Text(model.collection.collectionOrderRef ??
''),
180 padding: const pw.EdgeInsets.all(8),
183 style: pw.TextStyle(fontWeight: pw.FontWeight.bold),
187 padding: const pw.EdgeInsets.all(8),
188 child: pw.Text(
'Deferred Payment'),
195 pw.SizedBox(height: 25),
198 pw.TableHelper.fromTextArray(
206 data: List.generate(1, (index) {
208 model.product ??
'--',
209 '${model.quantityReceived ?? ''} Kg',
210 '${model.quantityBilled ?? ''} Kg',
214 headerStyle: pw.TextStyle(fontWeight: pw.FontWeight.bold),
215 cellAlignment: pw.Alignment.centerLeft,
220 pw.SizedBox(height: 30),
222 mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
223 children: [directorSignature, collectorSignature],
225 pw.SizedBox(height: 30),
232 mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
235 pw.SizedBox(width: 10),
238 pw.SizedBox(height: 10.sp),
240 'STRICTLY CONFIDENTIAL',
242 fontSize: 8, fontWeight: pw.FontWeight.normal,
243 color:
const PdfColor(0.5, 0.5, 0.5),
256 final output = await getTemporaryDirectory();
257 final file = File(
'${output.path}/collection_voucher_document.pdf');
258 await file.writeAsBytes(await pdf.save());
260 OpenFile.open(file.path);
class App extends StatefulWidget build(BuildContext context)
static const String directorSign
static final UserInfoService instance
Future< void > generateCollectionVoucher(CollectionVoucherDocumentModel model) async