thermal_lib
Lightweight Flutter helper for Bluetooth thermal printers.
- List paired Bluetooth devices
- Connect / disconnect
- Open cash drawer
- Print a receipt from any Flutter widget (offstage render)
- Save a receipt image (PNG) from any widget
Install
Add to your app pubspec.yaml:
dependencies:
thermal_lib: ^0.0.1
If using a local path while iterating:
dependencies:
thermal_lib:
path: ../thermal_lib
Quick start
import 'package:thermal_lib/thermal_lib.dart';
// 1) List and connect
final devices = await ThermalPrinter.instance.listPaired();
await ThermalPrinter.instance.connect(devices.first.macAdress);
// 2) Print from any widget
await ThermalPrinter.instance.printReceipt(
context,
SizedBox(width: 288, child: MyReceiptWidget()),
);
// 3) Open drawer
await ThermalPrinter.instance.openDrawer();
// 4) Save receipt PNG
final path = await ThermalPrinter.instance.saveReceipt(
context,
SizedBox(width: 288, child: MyReceiptWidget()),
'receipt.png',
);
// 5) Disconnect
await ThermalPrinter.instance.disconnect();
MyReceiptWidget can be any widget tree. The library renders it offstage, rasterizes it, and prints it as a bitmap for high compatibility with ESC/POS printers.
Notes
- Defaults target 80mm printers (≈576 px). Adjust
logicalWidth,pixelRatio, andPaperSizeas needed. - Requires
print_bluetooth_thermalfor I/O andesc_pos_utilsfor raster output.
License
MIT