barcode method
List<int>
barcode(
- Barcode barcode, {
- int? width,
- int? height,
- BarcodeFont? font,
- BarcodeText textPos = BarcodeText.below,
- PosAlign align = PosAlign.center,
Print a barcode
width
range and units are different depending on the printer model (some printers use 1..5).
height
range: 1 - 255. The units depend on the printer model.
Width, height, font, text position settings are effective until performing of ESC @, reset or power-off.
Implementation
List<int> barcode(
Barcode barcode, {
int? width,
int? height,
BarcodeFont? font,
BarcodeText textPos = BarcodeText.below,
PosAlign align = PosAlign.center,
}) {
List<int> bytes = [];
// Set alignment
bytes += setStyles(PosStyles().copyWith(align: align));
// Set text position
bytes += cBarcodeSelectPos.codeUnits + [textPos.value];
// Set font
if (font != null) {
bytes += cBarcodeSelectFont.codeUnits + [font.value];
}
// Set width
if (width != null && width >= 0) {
bytes += cBarcodeSetW.codeUnits + [width];
}
// Set height
if (height != null && height >= 1 && height <= 255) {
bytes += cBarcodeSetH.codeUnits + [height];
}
// Print barcode
final header = cBarcodePrint.codeUnits + [barcode.type!.value];
if (barcode.type!.value <= 6) {
// Function A
bytes += header + barcode.data! + [0];
} else {
// Function B
bytes += header + [barcode.data!.length] + barcode.data!;
}
return bytes;
}