2024-02-22 17:16:19 +06:30
|
|
|
import 'dart:io';
|
2025-03-26 15:51:47 +06:30
|
|
|
import 'package:fcs/pages/main/util.dart';
|
2024-02-22 17:16:19 +06:30
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
import 'package:open_file/open_file.dart';
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
import 'package:pdf/pdf.dart';
|
|
|
|
|
import 'package:pdf/widgets.dart' as pw;
|
|
|
|
|
|
|
|
|
|
import '../domain/entities/carton.dart';
|
|
|
|
|
|
|
|
|
|
Future<void> generateCartonPdf(Carton carton) async {
|
|
|
|
|
var myTheme = pw.ThemeData.withFont(
|
|
|
|
|
base:
|
|
|
|
|
pw.Font.ttf(await rootBundle.load("assets/fonts/OpenSans-Regular.ttf")),
|
|
|
|
|
bold: pw.Font.ttf(await rootBundle.load("assets/fonts/OpenSans-Bold.ttf")),
|
|
|
|
|
italic:
|
|
|
|
|
pw.Font.ttf(await rootBundle.load("assets/fonts/OpenSans-Italic.ttf")),
|
|
|
|
|
boldItalic: pw.Font.ttf(
|
|
|
|
|
await rootBundle.load("assets/fonts/OpenSans-BoldItalic.ttf")),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final doc = pw.Document(
|
|
|
|
|
theme: myTheme,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
PdfPageFormat format =
|
|
|
|
|
const PdfPageFormat(PdfPageFormat.inch * 3, PdfPageFormat.inch * 1);
|
|
|
|
|
doc.addPage(pw.Page(
|
|
|
|
|
pageFormat: format,
|
|
|
|
|
build: (pw.Context context) {
|
|
|
|
|
return pw.Padding(
|
|
|
|
|
padding: const pw.EdgeInsets.all(5),
|
|
|
|
|
child: pw.Row(
|
|
|
|
|
mainAxisAlignment: pw.MainAxisAlignment.start,
|
|
|
|
|
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
|
|
|
|
children: <pw.Widget>[
|
|
|
|
|
pw.BarcodeWidget(
|
|
|
|
|
width: 50,
|
|
|
|
|
height: 50,
|
|
|
|
|
color: PdfColor.fromHex("#000000"),
|
|
|
|
|
barcode: pw.Barcode.qrCode(),
|
2024-02-28 17:47:47 +06:30
|
|
|
data: carton.cartonNumber ?? ""),
|
2024-02-22 17:16:19 +06:30
|
|
|
pw.Padding(
|
|
|
|
|
padding: const pw.EdgeInsets.all(5),
|
|
|
|
|
child: pw.Column(
|
|
|
|
|
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
pw.Text(carton.cartonNumber!,
|
|
|
|
|
style: pw.TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
)),
|
2024-09-25 21:49:09 +06:30
|
|
|
pw.Text(carton.consigneeName!,
|
2024-02-22 17:16:19 +06:30
|
|
|
style: pw.TextStyle(
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
)),
|
2024-02-26 17:26:25 +06:30
|
|
|
pw.SizedBox(height: 3),
|
2025-03-26 15:51:47 +06:30
|
|
|
pw.Text(
|
|
|
|
|
"${twoDecimalFormatted(double.tryParse(removeTrailingZeros(carton.actualWeight)) ?? 0)} lb",
|
2024-02-22 17:16:19 +06:30
|
|
|
style: pw.TextStyle(
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
color: PdfColor.fromInt(0xFF757575)))
|
|
|
|
|
]),
|
|
|
|
|
),
|
|
|
|
|
]));
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
List<int> d = await doc.save();
|
|
|
|
|
final path = (await getExternalStorageDirectory())?.path ?? "";
|
|
|
|
|
final file = File("$path/${carton.cartonNumber}.pdf");
|
|
|
|
|
await file.writeAsBytes(d, flush: true);
|
|
|
|
|
OpenFile.open(file.path);
|
|
|
|
|
}
|