Sunmi Flutter Helper

A Flutter plugin for printing rich thermal receipts on Sunmi POS devices with support for text, QR codes, barcodes, images, and more using the official PrinterX SDK.


๐Ÿ›  Features

  • Print Text (with style)
  • Print QR Code
  • Print Barcode
  • Print Image
  • Print Table Columns
  • Print Lines (solid, dotted, empty)
  • NFC & Scanner Stream Support

๐Ÿ“ฆ Installation

Add to your pubspec.yaml:

dependencies:
  sunmi_flutter_helper: ^0.0.8

โœ… Printer Connection

bool isConnected = await SunmiFlutterHelper.isPrinterConnected();

๐Ÿ“ Print Text

await SunmiFlutterHelper.printText(
  text: "ABCD Company",
  align: "center",
  bold: true,
  underline: true,
  size: 16,
);

Parameters

Name Type Description
text String Text to print (required)
align String Alignment: "left", "center", "right"
bold bool Bold text
underline bool Underlined text
size int Font size (default: 16)
widthRatio int Width ratio (default: 1)
heightRatio int Height ratio (default: 1)
letterSpace int Space between letters
strikethrough bool Strike-through text

๐Ÿ”ฒ Print QR Code

await SunmiFlutterHelper.printQrCode(
  qrText: "https://yourdomain.com",
  align: "center",
  width: 250,
  height: 250,
);

Parameters

Name Type Description
qrText String Text to encode in QR (required)
align String Alignment: "left", "center", "right"
width int Width in pixels
height int Height in pixels
dot int Dot size (1-8)
errorLevel String QR error correction level: L, M, Q, H

๐Ÿงพ Print Barcode

await SunmiFlutterHelper.printBarcode(
  data: "123456789012",
  align: "center",
  width: 300,
  height: 100,
);

Parameters

Name Type Description
data String Barcode content (required)
align String "left", "center", "right"
width int Width in pixels
height int Height in pixels
readable String Human-readable mode: ONE, TWO, or THREE

๐Ÿ–ผ Print Image

Uint8List imageBytes = await loadImageAsset('assets/logo.jpg');
await SunmiFlutterHelper.printImage(
  image: imageBytes,
  align: 'center',
  width: 384
);

Parameters

Name Type Description
image Uint8List Image bytes (required)
align String "left", "center", "right"
width int Width in pixels
height int Height in pixels
threshold int Black & white threshold (optional)

๐Ÿ“Š Print Columns

await SunmiFlutterHelper.printColumns(
  texts: ['Item', 'Qty', 'Price'],
  weights: [3, 1, 2],
  align: 'left',
);

Parameters

Name Type Description
texts List Column texts (required)
weights List Column width weights (required)
align String "left", "center", "right"

โž– Print Line

await SunmiFlutterHelper.printLine(type: "dotted", height: 3);

Parameters

Name Type Description
type String Type of line: "solid", "dotted", "empty"
height int Height of the line

๐Ÿ“ก Streams

SunmiFlutterHelper.scanStream.listen((code) {
  print("Scanned: $code");
});

SunmiFlutterHelper.nfcStream.listen((nfcData) {
  print("NFC: $nfcData");
});

โœ… Requirements

  • Flutter 3.0+
  • Android 11+ on Sunmi device
  • Permissions: (Optional)
    <uses-permission android:name="android.permission.NFC" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    

๐Ÿงช Example App

See /example folder for a full working app.


๐Ÿ‘จโ€๐Ÿ’ป Maintainer

4Brains Technologies
https://www.4brains.in
For support: [email protected]


๐Ÿ“„ License

MIT