x_printer 0.0.4 copy "x_printer: ^0.0.4" to clipboard
x_printer: ^0.0.4 copied to clipboard

With this plugin you can connect to POS printers and print text, images, qrcode and barcode.

Introduction #

XPrinter is a printer plugin for Flutter, a mobile SDK to help developers build bluetooth thermal printer apps or features for both iOS and Android.

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.

Getting Started #

To use this plugin:

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

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 XPrinter instance

final plugin = XPrinter();

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();
4
likes
0
points
45
downloads

Publisher

unverified uploader

Weekly Downloads

With this plugin you can connect to POS printers and print text, images, qrcode and barcode.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on x_printer