sunmi_flutter_helper 0.0.5
sunmi_flutter_helper: ^0.0.5 copied to clipboard
Flutter plugin for Sunmi V2s Plus printers and scanners.
Sunmi Flutter Helper Plugin #
A Flutter plugin for printing rich thermal receipts on Sunmi Android devices, supporting text, QR codes, barcodes, images, columns, scanner, and NFC features.
Supports:
- Text (with styling)
- QR Code
- Barcode
- Bitmap image
- Dividing lines (solid, dotted, empty)
- Column layout (e.g. item, qty, price)
- NFC reading (RTD_TEXT and RTD_URI)
- Barcode/QR scanning via broadcast
๐ Getting Started #
1. Add to pubspec.yaml #
dependencies:
sunmi_flutter_helper: ^0.0.2
2. Android Setup #
Ensure your app is running on a Sunmi device with Android. Add permissions if required:
<uses-permission android:name="android.permission.BLUETOOTH" />
3. Assets (Optional - for image printing) #
flutter:
assets:
- assets/images/logo.jpg
๐จ Features & Usage #
โ Check Printer Connection #
bool isConnected = await SunmiFlutterHelper.isPrinterConnected();
๐ Print Text #
await SunmiFlutterHelper.printText({
'text': "Welcome to Sunmi",
'align': "center",
'bold': true,
'underline': true,
'size': 18,
});
๐ฆ Print QR Code #
await SunmiFlutterHelper.printQrCode({
'qrText': 'https://yourdomain.com',
'align': 'center',
'width': 250,
'height': 250,
});
๐งพ Print Barcode #
await SunmiFlutterHelper.printBarcode({
"data": "123456789012",
"align": "center",
"width": 300,
"height": 100,
"readable": "TWO" // Options: ONE, TWO, THREE
});
๐ผ Print Image #
Uint8List bytes = await loadImageAsset('assets/images/logo.jpg');
await SunmiFlutterHelper.printImage({
"image": bytes,
"align": "center",
"width": 384 // auto-maintains aspect ratio
});
๐งฑ Print Dividing Line #
await SunmiFlutterHelper.printLine({'type': 'solid', 'height': 4});
await SunmiFlutterHelper.printLine({'type': 'dotted', 'height': 2});
await SunmiFlutterHelper.printLine({'type': 'empty', 'height': 10});
๐ Print Table Columns #
await SunmiFlutterHelper.printColumns({
'texts': ['Item', 'Qty', 'Amount'],
'weights': [3, 1, 2],
'align': 'right'
});
๐ Scanner Support #
Listen to scanned barcode/QR code data using Sunmi scanner broadcast mode.
StreamSubscription? scanSubscription;
void startScanListener() {
scanSubscription = EventChannel("sunmi_flutter_helper/scanStream")
.receiveBroadcastStream()
.listen((data) {
print("Scanned code: \$data");
});
}
void stopScanListener() {
scanSubscription?.cancel();
}
๐ถ NFC Reader Support #
Read NFC tags (RTD_TEXT or RTD_URI records).
StreamSubscription? nfcSubscription;
void startNfcListener() {
nfcSubscription = EventChannel("sunmi_flutter_helper/nfcStream")
.receiveBroadcastStream()
.listen((data) {
print("NFC Data: \$data"); // May be a list of text and/or URI
});
}
void stopNfcListener() {
nfcSubscription?.cancel();
}
๐ Available Parameters #
๐ค Text Printing (printText) #
| Parameter | Type | Description | Example |
|---|---|---|---|
text |
String |
Required. The text to print | "Hello World" |
align |
String |
Optional. "left", "center", "right" |
"center" |
bold |
bool |
Optional. Bold style | true |
underline |
bool |
Optional. Underline text | true |
strikethrough |
bool |
Optional. Strike through text | false |
italics |
bool |
Optional. Italics style | false |
size |
int |
Optional. Font size (default: 16) | 18 |
widthRatio |
int |
Optional. Width scale factor | 1 |
heightRatio |
int |
Optional. Height scale factor | 1 |
letterSpace |
int |
Optional. Extra spacing between letters | 0 |
๐ Dividing Line (printLine) #
| Parameter | Type | Description | Values |
|---|---|---|---|
type |
String |
Required. Type of line | "solid", "dotted", "empty" |
height |
int |
Optional. Height of the line in pixels | 4, 8, etc. |
๐ฆ QR Code (printQrCode) #
| Parameter | Type | Description | Example |
|---|---|---|---|
qrText |
String |
Required. Data to encode | "https://example.com" |
align |
String |
Optional. "left", "center", "right" |
"center" |
width |
int |
Optional. Width of QR | 250 |
height |
int |
Optional. Height of QR | 250 |
dot |
int |
Optional. Dot density | 4 |
errorLevel |
String |
Optional. Error correction level | "L", "M", "Q", "H" |
๐งพ Barcode (printBarcode) #
| Parameter | Type | Description | Example |
|---|---|---|---|
data |
String |
Required. Barcode string | "123456789012" |
align |
String |
Optional. "left", "center", "right" |
"center" |
width |
int |
Optional. Width in pixels | 300 |
height |
int |
Optional. Height in pixels | 100 |
readable |
String |
Optional. Human-readable position | "ONE", "TWO", "THREE" |
๐ผ Image (printImage) #
| Parameter | Type | Description | Example |
|---|---|---|---|
image |
Uint8List |
Required. Byte data of the image | Uint8List.fromList(...) |
align |
String |
Optional. "left", "center", "right" |
"center" |
width |
int |
Optional. Target width in pixels | 384 |
height |
int |
Optional. Target height in pixels | โ |
threshold |
int |
Optional. Threshold for binarization | 200 |
๐ Columns (printColumns) #
| Parameter | Type | Description |
|---|---|---|
texts |
List<String> |
Required. Texts per column |
weights |
List<int> |
Required. Weight for each column |
align |
String |
Optional. "left", "center", "right" |
๐ Requirements #
- Android 11+
- Tested on: Sunmi Android devices
- Flutter 3.0+
๐จโ๐ป Maintainer #
4Brains Technologies
https://www.4brains.in
For support or customization: [email protected]
๐ License #
MIT License