smart_printer_flutter 0.1.0 copy "smart_printer_flutter: ^0.1.0" to clipboard
smart_printer_flutter: ^0.1.0 copied to clipboard

A Flutter plugin to print text, pdf, barcodes, and QR codes to thermal label and POS printers using TSPL, ZPL, ESC/POS.

Introduction #

smart_printer_flutter is a printer plugin for Flutter, a mobile SDK to help developers build bluetooth thermal printer apps or features for both iOS and Android.
Currently supports ESC/POS commands, and TSPL (on development) for label printers.

⚠️ Note: iOS plugin is under development. Some features may not be available yet.

Features #

Feature Android iOS Description
Scan Starts scanning for Bluetooth devices.
Connect Establishes a connection to the Bluetooth printer.
Disconnect Cancels an active or pending connection to the printer.
State Stream of state changes for the Bluetooth device.
Print Text Prints text with various formatting options.
Print QR Code Prints a QR code with specified data and error correction.
Print Barcode Prints a barcode with specified type and content.
Print Image Prints images from base64 encoded strings.
Cut Paper Sends a command to the printer to cut the paper.
Monitor Printer Status Streams updates on printer status and peripherals.
Is Scanning Stream Streams the scanning status of the printer.
Is Connected Checks if the printer is currently connected.
TSPL (Label Printer) 🚧 in progress Add support for TSPL command set (labels, stickers, etc).

Getting Started #

To use this plugin:

  • add dependency to your pubspec.yaml file.
dependencies:
  flutter:
    sdk: flutter
  smart_printer_flutter:

Add permissions for Bluetooth #

We need to add permission to use Bluetooth and access location:

iOS

In the ios/Runner/Info.plist let’s add:

	<dict>
	    <key>NSBluetoothAlwaysUsageDescription</key>
	    <string>Need BLE permission</string>
	    <key>NSBluetoothPeripheralUsageDescription</key>
	    <string>Need BLE permission</string>
	    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
	    <string>Need Location permission</string>
	    <key>NSLocationAlwaysUsageDescription</key>
	    <string>Need Location permission</string>
	    <key>NSLocationWhenInUseUsageDescription</key>
	    <string>Need Location permission</string>

Usage #

Init a SmartPrinterFlutter instance

final plugin = SmartPrinterFlutter();

scan

// start scan
plugin.startScan();

// get peripherals
ListView.builder(
    itemBuilder: (context, index) {
        final peripheral = peripherals[index];
        return ListTile(
            title: Text(peripheral.name ?? ''),
            subtitle: Text(peripheral.uuid ?? ''),
        );
    },
    itemCount: peripherals.length,
)

connect

plugin.connect(peripheral.uuid!);

disconnect

plugin.disconnect();

print text

plugin.printText('=======================================');
plugin.printText("Left");
plugin.printText(
    "Center",
    align: PTextAlign.center,
);
plugin.printText(
    "Right",
    align: PTextAlign.right,
);

plugin.printText('=======================================');
plugin.printText("FontB", attribute: PTextAttribute.fontB);
plugin.printText("Bold", attribute: PTextAttribute.bold);
plugin.printText(
    "Underline",
    attribute: PTextAttribute.underline,
);
plugin.printText(
    "Underline2",
    attribute: PTextAttribute.underline2,
);
plugin.printText('=======================================');
plugin.printText(
    "W1",
    width: PTextW.w2,
    height: PTextH.h2,
);
plugin.printText(
    "W2",
    width: PTextW.w2,
    height: PTextH.h2,
);
plugin.printText(
    "W3",
    width: PTextW.w3,
    height: PTextH.h3,
);
plugin.printText(
    "W4",
    width: PTextW.w4,
    height: PTextH.h4,
);

print image

"You should resize the image to fit each type of printer. For some models, printing an image that is too wide may result in errors."

plugin.printImage(base64Image);

cut paper

plugin.cutPaper();
2
likes
0
points
69
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to print text, pdf, barcodes, and QR codes to thermal label and POS printers using TSPL, ZPL, ESC/POS.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, permission_handler, plugin_platform_interface

More

Packages that depend on smart_printer_flutter

Packages that implement smart_printer_flutter