update printer

This commit is contained in:
Efril
2026-05-25 20:35:40 +07:00
parent 56e720e253
commit 6d9377f4ab
8 changed files with 185 additions and 44 deletions
@@ -9,11 +9,6 @@ class ReceiptComponentBuilder {
ReceiptComponentBuilder({required this.generator, this.paperSize = 58});
/// Get separator line based on paper size
String get _separator => paperSize == 80
? '------------------------------------------------'
: '--------------------------------';
/// Print text centered with custom style
List<int> textCenter(
String text, {
@@ -48,11 +43,21 @@ class ReceiptComponentBuilder {
);
}
/// Characters per line based on paper size (always size1 font)
String get _separatorLine => paperSize == 80
? '------------------------------------------------'
: '--------------------------------';
/// Print separator line
List<int> separator({bool bold = false}) {
return generator.text(
_separator,
styles: PosStyles(bold: bold, align: PosAlign.center),
_separatorLine,
styles: PosStyles(
bold: bold,
align: PosAlign.center,
height: PosTextSize.size1,
width: PosTextSize.size1,
),
);
}
@@ -116,6 +121,10 @@ class ReceiptComponentBuilder {
return generator.feed(count);
}
/// Helper: returns size2 for 80mm paper, size1 for 58mm
PosTextSize get _titleSize =>
paperSize == 80 ? PosTextSize.size2 : PosTextSize.size1;
/// Print header (outlet info)
List<int> header({
required String outletName,
@@ -127,8 +136,8 @@ class ReceiptComponentBuilder {
bytes += textCenter(
outletName,
bold: true,
height: PosTextSize.size1,
width: PosTextSize.size1,
height: _titleSize,
width: _titleSize,
);
bytes += textCenter(address);
bytes += textCenter(phoneNumber);
@@ -143,8 +152,8 @@ class ReceiptComponentBuilder {
bytes += textCenter(
printerType,
bold: true,
height: PosTextSize.size1,
width: PosTextSize.size1,
height: _titleSize,
width: _titleSize,
);
return bytes;
@@ -168,21 +177,16 @@ class ReceiptComponentBuilder {
}) {
List<int> bytes = [];
bytes += row2Columns('Nomor', orderNumber, leftWidth: 4, rightWidth: 8);
bytes += row2Columns('Nomor', orderNumber);
bytes += row2Columns('Pelanggan', customerName);
bytes += row2Columns('Kasir', cashierName, leftWidth: 4, rightWidth: 8);
bytes += row2Columns('Kasir', cashierName);
if (paymentMethod != null) {
bytes += row2Columns(
'Pembayaran',
paymentMethod,
leftWidth: 8,
rightWidth: 4,
);
bytes += row2Columns('Pembayaran', paymentMethod);
}
if (tableNumber != null && tableNumber.isNotEmpty) {
bytes += row2Columns('Meja', tableNumber, leftWidth: 8, rightWidth: 4);
bytes += row2Columns('Meja', tableNumber);
}
return bytes;
@@ -193,7 +197,7 @@ class ReceiptComponentBuilder {
List<int> bytes = [];
bytes += separator();
bytes += textCenter(type, bold: true);
bytes += textCenter(type, bold: true, height: _titleSize, width: _titleSize);
bytes += separator();
return bytes;
@@ -214,7 +218,7 @@ class ReceiptComponentBuilder {
? '$productName ($variantName)'
: productName;
bytes += textLeft(displayName);
bytes += textLeft(displayName, bold: paperSize == 80);
bytes += row2Columns(
'$quantity x $unitPrice',
totalPrice,
@@ -263,19 +267,27 @@ class ReceiptComponentBuilder {
bytes += textCenter(
message,
bold: true,
height: PosTextSize.size1,
width: PosTextSize.size1,
height: _titleSize,
width: _titleSize,
);
if (kDebugMode) {
bytes += textCenter("$paperSize MM", );
bytes += textCenter("$paperSize MM");
}
bytes += feed(paperSize == 80 ? 3 : 1);
bytes += generator.cut();
return bytes;
}
/// Cut paper without printing footer message
List<int> cutOnly() {
List<int> bytes = [];
bytes += feed(paperSize == 80 ? 3 : 1);
bytes += generator.cut();
return bytes;
}
/// Print QR Code
List<int> qrCode(String data, {PosAlign align = PosAlign.center}) {
return generator.qrcode(data, align: align);