flutter_esc_pos_bluetooth_universal 1.0.0
flutter_esc_pos_bluetooth_universal: ^1.0.0 copied to clipboard
Print receipts on ESC/POS thermal Bluetooth printers (BLE and Classic SPP) from Android, iOS, macOS, Windows, Linux and Flutter Web, with one API.
1.0.0 #
First release of flutter_esc_pos_bluetooth_universal, a complete rewrite of esc_pos_bluetooth / flutter_esc_pos_bluetooth. It is the Bluetooth companion of flutter_esc_pos_network_universal and shares its API.
- Universal support: one API for Android, iOS, macOS, Windows, Linux and Flutter Web.
- BLE printers through
flutter_blue_plus2.x on every platform; in the browser it uses Web Bluetooth. - Bluetooth Classic (SPP) printers, the kind most 58/80 mm POS printers are:
- Android, Windows, macOS and Linux use
flutter_classic_bluetooth. - Chromium browsers use Web Serial over Bluetooth RFCOMM (desktop Chrome 117+), with no browser extension.
- On macOS, where RFCOMM connections can stall, a Classic printer is reached through its BLE side when it has one (most are dual-mode), found by name. RFCOMM is the fallback.
- iOS is BLE only, because Apple allows Classic Bluetooth only for MFi accessories.
- Android, Windows, macOS and Linux use
- Characteristic selection: tries a table of common printer services (
defaultBlePrinterServices), then any writable characteristic. When several known ones match (the Deli ES421 takes data on 18F0 and FF00 while its ISSC UART accepts writes and drops them), a status request picks the one the printer answers on. The choice is saved on the printer. Apps can add their own UUIDs throughbleServices. - Clean widget receipts, sent exactly as the network package sends them: one image of
ESC *column bands, then a feed and a cut. No raster commands, nothing that depends on what the receipt holds.- No white lines: the bands are bracketed by
ESC 3 0/ESC 2, so each line feed moves the paper exactly one band. - Every part prints, no random characters: Bluetooth has no TCP window to slow the sender, so every write is paced to the print speed (
WritePacing: 50 mm/s on text, 2.5 mm/s on dense bands, 4 kB burst). A band is dense when a quarter of its bits are set, measured from the picture itself, so any logo, QR code or barcode gets its time. - Timing that follows the printer: a printer prints a band only once all of it has arrived, so each band goes out at link speed and the next waits for its print time. Paying for a band while sending it left the printer idle while a graphic trickled in, then flooded it with the text after the graphic while it was still printing it, and a 58 mm printer threw that text away. Each byte is charged once, even when the radio asks for a write to be retried.
- Explicit left alignment at the start of every ticket and no
ESC @, as in the network package. - Built straight from the captured 8-bit pixels: the same dots as
Generator.image, trimmed of blank columns, about 20 times faster, and immune to the 16-bit captures that garbled receipts on real iPhones. - Bytes that would spell a real-time command (
DLE EOT,DLE ENQ,DLE DC4) never appear in image data. gapMmleaves blank paper below the receipt for tearing by hand.
- No white lines: the bands are bracketed by
- Reliable writes:
- BLE chunks follow the negotiated MTU and step down when a write is rejected for its length; a write refused for a busy radio is retried at the same size.
- The last BLE chunk is sent with response when possible, so the ticket has arrived before the link closes.
- On the web, BLE writes go in batches with one confirmed write every
webBleBatchSizechunks, as Chrome on macOS silently drops unconfirmed writes its queue cannot hold. - Web Serial opens the port with a 16 KB buffer and waits until the browser has sent every byte before closing it.
- Raw ESC/POS:
printTicketsends bytes from the re-exportedGenerator, paced by the dots they print. - Discovery: BLE and Classic scanning merged into one list (paired first, then by signal strength),
pairedPrinters(), andrequestPrinter()for the browser chooser. - Saved printers:
BluetoothPrinterconverts to and from JSON. - Platform insight:
capabilities,checkAvailability(),requestPermissions(),connectionStatus,lastErrorandlastPrint. - Clear results:
PosPrintResultis an enum with a readablemsg, its shared names matching the network package. - Paper sizes: 58 mm, 72 mm and 80 mm.
- Example app for every platform.
Migrating from esc_pos_bluetooth / flutter_esc_pos_bluetooth #
PrinterBluetoothis nowBluetoothPrinter, a plain data class withid,name,type(ble/classic) andtoJson()/fromJson().PrinterBluetoothManager()now needs alicense(License.nonprofitorLicense.commercial), passed toflutter_blue_plus, whose own licence requires it.startScan(Duration)is nowstartScan({timeout})and returns aFuture.selectPrinteris asynchronous as well.printTickettakes raw ESC/POS bytes (List<int>). Build them with the re-exportedGenerator; the oldTicketclass is gone.queueSleepTimeMs/chunkSizeBytesare replaced byBluetoothWriteOptions.PosPrintResultis an enum. Compare with==as before, and read the text frommsg.flutter_blueandrxdartare no longer dependencies.
Requirements #
- Dart 3.12+ and Flutter 3.44+ (required by
flutter_classic_bluetooth). flutter_blue_plusis under the FlutterBluePlus License: free for personal, nonprofit and educational use; for-profit use needs a commercial licence from its authors.
Based on the original work by Andrey Ushakov (esc_pos_bluetooth, BSD-3).