printBarcode static method
Future<bool>
printBarcode(
- String data,
- BarcodeType type, {
- int height = 100,
- int width = 2,
- Alignment alignment = Alignment.center,
- BarcodeTextPosition textPosition = BarcodeTextPosition.below,
Print a barcode.
data: Content to encode in the barcodetype: Barcode type (CODE128, QR, etc.)height: Barcode height in dotswidth: Barcode module width in dotsalignment: 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;
}
}