sunmi_flutter_helper 0.0.6 copy "sunmi_flutter_helper: ^0.0.6" to clipboard
sunmi_flutter_helper: ^0.0.6 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
size int Optional. Font size (default: 16) 18

๐Ÿ“ 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

๐Ÿงพ 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