printDynamic method
Universal dynamic printing method
Prints any type of document (receipt, report, invoice, dispatch, etc.) based on the provided args map. Fields not provided are automatically skipped.
args - Map containing document data:
- businessName: Business name (centered, bold, large)
- header: Document header/title (centered, bold)
- subHeader: Document subtitle (centered)
- fields: Map of key-value pairs to print
- items: List of items to print as table
- totals: Map of totals (Subtotal, Tax, Total, etc.)
- footer: Footer text (centered, small)
- qrCodeField: Field name whose value should be rendered as QR code
- layoutStyle: 'simple', 'detailed', or 'compact' (default: 'detailed')
bothCopies - If true, prints both customer and merchant copies with a pause between them
pauseBetweenCopies - Number of seconds to pause between copies (default: 5 seconds)
Example:
await printDynamic({
'businessName': 'mesh Logistics',
'header': 'DISPATCH RECEIPT',
'subHeader': 'Warehouse #3 - Nairobi',
'fields': {
'Customer Name': 'John Mwangi',
'Loader': 'Peter Otieno',
'Weight': '320 KG',
},
'items': [
{'Item': '20L Water', 'Qty': '2', 'Unit': '50', 'Total': '100'},
],
'totals': {'Total': 'KSH 130'},
'footer': 'Thank you for choosing mesh',
'qrCodeField': 'dispatchId',
'dispatchId': 'DSP-2025-001',
}, bothCopies: true, pauseBetweenCopies: 5);
Implementation
@override
Future<Map<String, dynamic>> printDynamic(
Map<String, dynamic> args, {
bool bothCopies = false,
int pauseBetweenCopies = 5,
}) async {
try {
final Map<String, dynamic> result = Map<String, dynamic>.from(
await channel.invokeMethod('printDynamic', {
'args': args,
'bothCopies': bothCopies,
'pauseBetweenCopies': pauseBetweenCopies,
}),
);
return result;
} on PlatformException catch (e) {
throw SmartPosException('Failed to print document: ${e.message}');
}
}