NiimbotLabelPrinter

August 15, 2024 ยท View on GitHub

NiimbotLabelPrinter is a Flutter package that enables printing labels using Niimbot label printers. This package provides a simple interface to connect to a Niimbot printer via Bluetooth, manage connections, and send print data.

Features

  • Request Bluetooth permissions.
  • Check if Bluetooth is enabled.
  • Connect and disconnect from a Niimbot printer.
  • Retrieve paired Bluetooth devices.
  • Send print data to the printer.

Installation

Add niimbot_label_printer to your pubspec.yaml:

dependencies:
  niimbot_label_printer: ^0.0.1

Usage

To use the NiimbotLabelPrinter plugin, follow these steps:

  1. Request Bluetooth permissions:
final bool result = await NiimbotLabelPrinter.requestPermissionGrant();
  1. Check if Bluetooth is enabled:
final bool result = await NiimbotLabelPrinter.bluetoothIsEnabled();
  1. Connect to a Niimbot printer:
final bool result = await NiimbotLabelPrinter.connect(device);
  1. Disconnect from a Niimbot printer:
final bool result = await NiimbotLabelPrinter.disconnect();
  1. Retrieve paired Bluetooth devices:
final List<BluetoothDevice> devices = await NiimbotLabelPrinter.getPairedDevices();
  1. Send print data to the printer:
final bool result = await NiimbotLabelPrinter.send(printData);
  1. Desconnect from a Niimbot printer:
final bool result = await NiimbotLabelPrinter.disconnect();

QR Code Generation

To generate QR codes, you should use the qr_flutter library. Add the following dependency to your pubspec.yaml:

dependencies:
  qr_flutter: ^4.1.0

API Reference

Methods

MethodDescription
getPlatformVersion()Returns the platform version of the device.
requestPermissionGrant()Requests Bluetooth permission and checks if it's granted.
bluetoothIsEnabled()Checks if Bluetooth is enabled on the device.
isConnected()Checks if the device is connected to a Niimbot printer.
getPairedDevices()Returns a list of paired Bluetooth devices.
connect(BluetoothDevice)Connects to a specified Bluetooth device.
disconnect()Disconnects from the currently connected Bluetooth device.
send(PrintData)Sends print data to the connected Niimbot printer.

Class: PrintData

ParameterTypeDescription
dataList<int>A list of integers representing the raw print data.
widthintThe width of the label in pixels.
heightintThe height of the label in pixels.
rotateboolIndicates whether the label should be rotated before printing.
invertColorboolIndicates whether the colors should be inverted before printing.
densityintThe density of the label.
labelTypeintThe type of label.

Example

In the example, you can print an image from the assets or create an image dynamically.

  • To print an image from the assets, load the image using AssetImage and capture the widget.
  • To create an image, use widgets like QrImage to generate content dynamically and then capture the widget.

Both methods allow you to generate the image you want to print and send it to the printer.


Foto

Here is an example of how the label looks:

Print label

Print label assets

Create label

Create label


Created With

This package was created using the following technologies:


Created with โค๏ธ by andresperezmelo ๐Ÿ˜Š Andres Perez Melo