printBarcodeWithCaption static method
Print a barcode with a caption.
Prints a barcode followed by a descriptive caption.
data: Content to encode in the barcodecaption: Descriptive text to print below the barcodetype: Barcode type (CODE128, QR, etc.)height: Barcode height in dotswidth: Barcode module width in dotsshowBarcodeText: Whether to show the barcode data as text
Returns true if printing was successful.
Implementation
static Future<bool> printBarcodeWithCaption(
String data, {
required String caption,
BarcodeType type = BarcodeType.code128,
int height = 100,
int width = 2,
bool showBarcodeText = true,
}) async {
try {
// First print the barcode
final barcodeResult = await printBarcode(
data,
type,
height: height,
width: width,
alignment: Alignment.center,
textPosition: showBarcodeText
? BarcodeTextPosition.below
: BarcodeTextPosition.none,
);
if (!barcodeResult) {
return false;
}
// Then print the caption (using imported PrinterText)
return await PrinterText.printCenteredText(
text: caption,
fontSize: 20,
);
} catch (e) {
print('Error printing barcode with caption: $e');
return false;
}
}