printBarcode static method

Future<bool> printBarcode(
  1. String data,
  2. BarcodeType type, {
  3. int height = 100,
  4. int width = 2,
  5. Alignment alignment = Alignment.center,
  6. BarcodeTextPosition textPosition = BarcodeTextPosition.below,
})

Print a barcode.

  • data: Content to encode in the barcode
  • type: Barcode type (CODE128, QR, etc.)
  • height: Barcode height in dots
  • width: Barcode module width in dots
  • alignment: Barcode alignment (left, center, right)
  • textPosition: Position of human-readable text

Returns true if printing was successful.

Implementation

static Future<bool> printBarcode(
  String data,
  BarcodeType type, {
  int height = 100,
  int width = 2,
  Alignment alignment = Alignment.center,
  BarcodeTextPosition textPosition = BarcodeTextPosition.below,
}) async {
  try {
    // Use the printer core to print the barcode
    return await PrinterCore.printBarcode(
      data,
      type: type.index,
      height: height,
      width: width,
      alignment: TextFormatter.convertAlignment(alignment),
      textPosition: textPosition.index,
    );
  } catch (e) {
    print('Error printing barcode: $e');
    return false;
  }
}