universal_thermal_printer 1.0.0
universal_thermal_printer: ^1.0.0 copied to clipboard
Universal Thermal Printer SDK for Flutter — Bluetooth & Network (WiFi/LAN) ESC/POS thermal printer support with text, QR, barcode, images, and built-in remote license activation.
1.0.0 #
Major expansion into a full, cross-industry thermal-printing SDK. Backward
compatible: ThermalPrinter, PrintTemplate, TemplateBuilder,
TemplateEngine, EscPosBuilder, LicenseManager keep their existing APIs.
Receipts (data-first API) #
- Added
Receipt— a simple, imperative builder to add a header, line items (item(name, qty, rate, amount)with autoqty × rate), a totals block (subtotal, taxes/discounts, grand total, tendered + auto-computed change), dividers, spacing, QR/barcodes, a logo image and date/time — then print withThermalPrinter.printReceipt(receipt, openDrawer: ...). Compiles to the existing template pipeline, so it inherits 58/80mm layout, non-Latin bitmap fallback, paper cut, the offline queue, retries and licensing. ReceiptItemStyle.qtyRateAmount(default) andReceiptItemStyle.nameAmountchoose the item-table columns;Receipt(currency: '₹')formats money.- Bluetooth reconnect fix:
BluetoothPrinterConnection.connect()now clears a lingering socket before reconnecting, fixing "failed to connect" on a second attempt after an unclean disconnect. - Bluetooth write fix: send the payload to
print_bluetooth_thermalas aList<int>in a single call. Passing aUint8Listmarshaled as a Javabyte[], causingbyte[] cannot be cast to java.util.Listand every write to fail. Removing the 200-byte app-level chunking also stops the plugin's per-call newline from being injected into QR/logo raster data, which had corrupted graphics that spanned a chunk boundary.
Connectivity #
- Added BLE (
connectBLE,flutter_blue_plus) and USB (connectUSB, Android host) transports alongside Bluetooth Classic and Network. - Replaced the abandoned
flutter_bluetooth_serial(incompatible with AGP 8/9) with the maintainedprint_bluetooth_thermalfor Bluetooth Classic.BluetoothPrinterConnection.getPairedDevices()now returnsList<PrinterDevice>. - USB is now opt-in, not bundled. The
usb_serialplugin is unmaintained and also breaks modern Android builds (jcenter()/ old Kotlin-plugin apply), so it was removed as a dependency. TheconnectUSB()API is preserved but reportsUnsupportedTransportExceptionuntil a maintained USB plugin (e.g.quick_usb) is wired in. This keeps the SDK building cleanly on all toolchains. - Network auto-discovery (
NetworkPrinterDiscovery) — no more typing IPs. - Auto-reconnect with exponential backoff (
autoReconnect,ReconnectPolicy). PrinterManager— hold multiple named printers (receipt/kitchen) and route jobs.- Real-time status (
queryStatus) — paper out / cover open / offline / low battery viaDLE EOT. - Offline print queue (
OfflinePrintQueue) — persists jobs and auto-flushes on reconnect.
Paper & hardware #
- Configurable
PrinterProfile— 58mm/80mm and label vs continuous; the template engine adapts column widths automatically. CommandProtocolabstraction (ESC/POS today; ZPL/TSPL/CPCL can be added without breaking the public API).
Industry templates #
- New composable elements:
TableElement,TaxBreakdownElement,AddressBlockElement,BarcodeLabelElement,BigNumberElement. PrebuiltTemplatesfor retail, restaurant KOT, logistics, pharmacy, parking, bank mini-statement, warehouse label, and queue token.
Internationalization #
- Automatic bitmap fallback for non-Latin scripts (Hindi/Arabic/Chinese…)
and symbols like
₹viaTextPainter; RTL support.
Reliability #
- Configurable retry (
RetryPolicy), typed exceptions (PaperOutException,PrinterOfflineException, …) exposed onPrintResult.exception, and an auditPrintJobLog.
Platform coverage #
PlatformSupportreports usable transports; unsupported transports fail with a clearUnsupportedTransportException(incl. the iOS MFi note). Identical public API across Android/iOS/Windows/Linux/macOS.
Licensing & DX #
- Transparent licensing: configure once with a license key; end users never see one. Free mode (10 bills/day) when no key is set.
- Firestore-direct verification on the free Spark plan (no Cloud Functions).
- Grace period so a transient outage doesn't block checkout.
- Admin CLI (
server/admin/admin.js) to issue/revoke/list keys and set expiry/app-lock/device caps. ReceiptPreviewwidget for on-screen print preview; rebuilt example app (printer picker → template gallery → live preview → print).
Original 0.0.x features (unchanged) #
- Bluetooth Classic printer support (Android)
- Network/WiFi printer support (TCP port 9100)
- Text, QR code, barcode printing
- Paper cut & cash drawer commands
- Remote license activation via Firebase Cloud Function
- Added custom template system:
PrintTemplate,TemplateBuilder,TemplateEngine - Support for text, image/logo, QR code, barcode, divider, spacer, date/time, and two-column row elements in a template
- Placeholder support (
{{key}}) resolved from a data map at print time - Templates are JSON-serializable — save and reuse layouts across prints
- Added
printer.printTemplate(template, data: {...}) - Added image printing (
EscPosBuilder.image) with automatic resize + monochrome dithering for logos/signatures