gpos720_printer

A Flutter plugin to integrate printing in the Gertec GPOS720.

gpos720

example

Features

Methods Implemented
checarImpressora ✔️
avancaLinha ✔️
imprimirTexto ✔️
imprimirImagem ✔️
imprimirImagemFiltrada ✔️
imprimirCodigoDeBarra ✔️
imprimirCodigoDeBarraImg ✔️
imprimirTodasFuncoes ✔️
imprimirEscPos ❌️

Requirements

  • Android minimum sdk version >= 22.
  • Flutter version >= 2.0.0.
  • Dart version >= 2.12.0.

Installation

Step 1

  • In the "/android/src/main/AndroidManifest.xml", add:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    ...
    <uses-feature android:name="android.hardware.usb.host" />
    ...
</manifest>

Step 2

The Android Gradle Plugin (AGP) doesn’t support direct local AAR dependencies in Android library projects due to how it packages the resulting AAR, so we need to do the following configurations.

  • In the "/android/app/libs/" directory, paste the two .aar dependencies used by this library. You can find them in this link.

  • Then in the "android/app/build.gradle", add:

...
Android{
    ...
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.aar'])
    }
}
...
  • Lastly in the "android/build.gradle", add:
...
allprojects {
    repositories {
        google()
        mavenCentral()
        flatDir {
            dirs 'libs'
        }
    }
}
...

Getting Started

Just instantiate the "Gpos720Printer" and invoke the desired functions as shown in this example project.

You must have a Gertec GPOS720 device to be able to use this plugin.

Instantiate:

Instantiate the "Gpos720Printer" object like this:

import 'package:gpos720_printer/gpos720_printer.dart';

void main() {
  Gpos720Printer gpos720Printer = Gpos720Printer();
}

Documentation

Methods:

Future<PrinterStatus> avancaLinha(int quantLinhas)

  • Description: Adds line breaks to the current printout.
  • Returns: A PrinterStatus enum indicating the printer’s status.
  • Parameters:
  1. quantLinhas: An Integer specifying the desired number of line breaks.
  • Throws: A PlatformException or a MissingPluginException.

Future<PrinterStatus> checarImpressora()

  • Description: Checks the printer’s status.
  • Returns: A PrinterStatus enum indicating the printer’s status.
  • Throws: A PlatformException or a MissingPluginException.

Future<PrinterStatus> imprimirCodigoDeBarra(String mensagem, int width, int height, BarcodeTypes barcodeType)

  • Description: Prints various types of barcodes.
  • Returns: A PrinterStatus enum indicating the printer’s status.
  • Parameters:
  1. mensagem: A String specifying the desired data on the barcode.
  2. width: An Integer specifying the desired width.
  3. height: An Integer specifying the desired height.
  4. barcodeTypes: A BarcodeTypes enum specifying the desired barcode type.
  • Throws: A PlatformException or a MissingPluginException.

Future<PrinterStatus> imprimirCodigoDeBarraImg(String mensagem, int width, int height, BarcodeTypes barcodeType)

  • Description: Prints various types of barcodes, rendering them as images.
  • Returns: A PrinterStatus enum indicating the printer’s status.
  • Parameters:
  1. mensagem: A String specifying the desired data on the barcode.
  2. width: An Integer specifying the desired width.
  3. height: An Integer specifying the desired height.
  4. barcodeTypes: A BarcodeTypes enum specifying the desired barcode type.
  • Throws: A PlatformException or a MissingPluginException.

Future<PrinterStatus> imprimirImagem(Uint8List data, int width, int height, {AlignmentTypes align = AlignmentTypes.center})

  • Description: Prints raw black and white images only. You can use the method binaryFilterWithDithering to apply a binary filter with dithering to the image.
  • Returns: A PrinterStatus enum indicating the printer’s status.
  • Parameters:
  1. data: A Uint8List with the raw data of the black and white image.
  2. width: An Integer specifying the desired width.
  3. height: An Integer specifying the desired height.
  4. align (optional): An AlignmentTypes enum specifying the desired alignment. By default, align will be center.
  • Throws: A PlatformException or a MissingPluginException.

Future<PrinterStatus> imprimirImagemFiltrada(Uint8List data, int width, int height, {AlignmentTypes align = AlignmentTypes.center, double? blackTolerance, double? ditheringTolerance})

  • Description: Apply a binary filter with dithering and print the raw image.
  • Returns: A PrinterStatus enum indicating the printer’s status.
  • Parameters:
  1. data: A Uint8List with the raw data of the image.
  2. width: An Integer specifying the desired width.
  3. height: An Integer specifying the desired height.
  4. align (optional): An AlignmentTypes enum specifying the desired alignment. By default, align will be center.
  5. blackTolerance (optional): A double representing the tolerance level for using black color. The default value is 0.34.
  6. ditheringTolerance (optional): A double representing the tolerance for using dithering to represent colors. The default value is 0.67.
  • Throws: A PlatformException or a MissingPluginException.

Future<PrinterStatus> imprimirTexto(String mensagem, {TextOptions? options, int size = defaultFontSize, Font? font, AlignmentTypes align = AlignmentTypes.left})

  • Description: Prints text.
  • Returns: A PrinterStatus enum indicating the printer’s status.
  • Parameters:
  1. mensagem: A String with the desired text to be printed.
  2. options (optional): A TextOptions specifying if the text will be render as bold, italic or underlined.
  3. size (optional): An Integer specifying the desired font size.
  4. Font (optional): A Font specifying the desired font to be used in the text.
  5. align (optional): An AlignmentTypes enum specifying the desired alignment. By default, align will be left.
  • Throws: A PlatformException or a MissingPluginException.

Future<PrinterStatus> imprimirTodasFuncoes(Uint8List data, int width, int height)

  • Description: Prints all printer functions.
  • Returns: A PrinterStatus enum indicating the printer’s status.
  • Parameters:
  1. data: A Uint8List with the raw data of the black and white image.
  2. width: An Integer specifying the desired width.
  3. height: An Integer specifying the desired height.
  • Throws: A PlatformException or a MissingPluginException.

Configuration parameters:

BarcodeTypes

An enum to indicate the type of barcode to be printed. Click here to consult the available types.

AlignmentTypes

An enum to indicate the type of barcode to be printed. Click here to consult the available types.

Font

An object to specify the desired font for printing. The constructor receives the font name as a parameter, and the font must be available in the assets folder under the directory "/fonts". By default, it is set to " NORMAL", click here to view the implementation.

TextOptions

An object that specifies the desired text decoration. It can add bold, italic, or underline styles. By default, all styles are set to false, click here to view the implementation.

Output:

PrinterStatus

An enum to indicate the current status of the printer, it can be parsed to a String using the ".getLabel" method. Click here to view the implementation.

ImageUtils:

binaryFilterWithDithering

A method that applies a binary filter with dithering to an image, converting it to black and white while using dithering to represent colors that are not too dark. The method takes the following parameters:

  • image: A Uint8List representing the image.
  • blackTolerance: A double representing the tolerance level for using black color. The default value is 0.34.
  • ditheringTolerance: A double representing the tolerance for using dithering to represent colors. The default value is 0.67.

Click here to view the implementation.

TODO

  • Implement plugin tests.
  • Print raw ESC/POS commands.