kurdish_reporting 1.0.4
kurdish_reporting: ^1.0.4 copied to clipboard
A package for generating reports in PDF, printing, exporting to Excel, and capturing images. Supports Kurdish and Arabic languages.
example/main.dart
// example/main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:kurdish_pdf/pdf.dart';
import 'package:kurdish_printing/printing.dart'; // For direct printing
import 'package:flutter_pdfview/flutter_pdfview.dart'; // For PDF preview
import 'package:kurdish_reporting/kurdish_reporting.dart'; // Import the reporting package
//import 'dart:typed_data'; // To handle byte data
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Invoice Test App',
theme: ThemeData(
primarySwatch: Colors.teal,
),
home: InvoiceTestPage(),
);
}
}
class InvoiceTestPage extends StatefulWidget {
@override
_InvoiceTestPageState createState() => _InvoiceTestPageState();
}
class _InvoiceTestPageState extends State<InvoiceTestPage> {
final PdfService _pdfService = PdfService(); // PDF generation service
Uint8List? _generatedPdf; // Store the generated PDF for preview
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Invoice Test App'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: _generatePdfPreview,
child: Text('Print Preview'),
),
ElevatedButton(
onPressed: _printInvoice,
child: Text('Print'),
),
],
),
),
);
}
// Generates the PDF and shows it in a preview screen
Future<void> _generatePdfPreview() async {
_generateInvoicePdf();
}
// Prints the invoice directly
Future<void> _printInvoice() async {
_generateInvoicePdf();
}
// Generates the invoice PDF using the PDF Service
// Future<Uint8List> _generateInvoicePdf() async {
Future<void> _generateInvoicePdf() async {
final reportData = ReportData(
companyName: 'ABC Company',
address: '123 Main St, City',
invoiceNumber: 'INV-1001',
date: '2024-01-01',
recipientName: 'John Doe',
amount: 250.00,
amountInWords: '',
note: 'Payment for services rendered',
account: '',
paid:
'تازە بکەیتەوە بەکارهێنانی بە بێ ڵڵا دەڵەوبا ڵاادەڵاڵ بەهۆی ئەم سکریپتەوە',
authorizedSignature: 'Manager',
language: 'ar', // or 'en', 'ar'
);
// // Generate PDF for A4 size
// final pdfDocument =
// await _pdfService.generatePaymentInvoice(reportData, 'A4');
// return pdfDocument.save();
// Generate the PDF using the PDF service
final pdfService = PdfService();
final pdfDocument =
await pdfService.generatePaymentInvoice(reportData, 'A4');
final pdfBytes = await pdfDocument.save();
// if (isPreview) {
if (true) {
// Handle print preview
if (kIsWeb) {
// On Web: Use the browser's built-in PDF viewer for preview
await Printing.layoutPdf(
onLayout: (PdfPageFormat format) async => pdfBytes);
} else {
// On Mobile/Desktop: Navigate to the PdfPreviewScreen for preview
//WAY 1
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PdfPreviewScreen(pdfBytes: pdfBytes),
),
);
//WAY 2
// On Mobile/Desktop: Print the PDF directly
// await Printing.layoutPdf(
// onLayout: (PdfPageFormat format) async => pdfBytes);
}
} else {
// Handle direct print
await Printing.layoutPdf(
onLayout: (PdfPageFormat format) async => pdfBytes);
}
}
}
// A separate screen to preview the PDF
class PdfPreviewScreen extends StatelessWidget {
final Uint8List pdfBytes;
PdfPreviewScreen({required this.pdfBytes});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('PDF Preview'),
),
body: PDFView(
pdfData: pdfBytes,
autoSpacing: true,
enableSwipe: true,
swipeHorizontal: true,
),
);
}
}