update printer checker
This commit is contained in:
@@ -9,26 +9,26 @@ class ReceiptComponentBuilder {
|
||||
|
||||
ReceiptComponentBuilder({required this.generator, this.paperSize = 58});
|
||||
|
||||
/// Helper: returns size2 for 80mm paper, size1 for 58mm
|
||||
PosTextSize get _titleSize =>
|
||||
paperSize == 80 ? PosTextSize.size3 : PosTextSize.size1;
|
||||
|
||||
/// Font type per paper size — easy to change here
|
||||
/// 58mm → fontA, 80mm → fontA
|
||||
PosFontType get _font =>
|
||||
paperSize == 80 ? PosFontType.fontA : PosFontType.fontA;
|
||||
paperSize == 80 ? PosFontType.fontB : PosFontType.fontA;
|
||||
|
||||
/// Text size for body — height size2 for 80mm to appear taller, size1 for 58mm
|
||||
PosTextSize get _bodySize =>
|
||||
PosTextSize get _bodyHeight =>
|
||||
paperSize == 80 ? PosTextSize.size2 : PosTextSize.size1;
|
||||
|
||||
/// Body width stays size1 always to prevent overflow
|
||||
PosTextSize get _bodyWidth => PosTextSize.size1;
|
||||
PosTextSize get _bodyWidth => paperSize == 80 ? PosTextSize.size2 : PosTextSize.size1;
|
||||
|
||||
/// Characters per line based on paper size (always size1 font)
|
||||
String get _separatorLine => paperSize == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------';
|
||||
/// Characters per line based on paper size and font
|
||||
String get _separatorLine {
|
||||
if (paperSize == 80) {
|
||||
return _font == PosFontType.fontB
|
||||
? '----------------------------------------------------------------'
|
||||
: '------------------------------------------------';
|
||||
} else {
|
||||
return _font == PosFontType.fontB
|
||||
? '------------------------------------------'
|
||||
: '--------------------------------';
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Basic text
|
||||
@@ -37,17 +37,18 @@ class ReceiptComponentBuilder {
|
||||
List<int> textCenter(
|
||||
String text, {
|
||||
bool bold = false,
|
||||
PosTextSize height = PosTextSize.size1,
|
||||
PosTextSize width = PosTextSize.size1,
|
||||
PosTextSize? height,
|
||||
PosTextSize? width,
|
||||
PosFontType? fontType,
|
||||
}) {
|
||||
return generator.text(
|
||||
text,
|
||||
styles: PosStyles(
|
||||
bold: bold,
|
||||
align: PosAlign.center,
|
||||
height: height,
|
||||
width: width,
|
||||
fontType: _font,
|
||||
height: height ?? _bodyHeight,
|
||||
width: width ?? _bodyWidth,
|
||||
fontType: fontType ?? _font,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -59,7 +60,7 @@ class ReceiptComponentBuilder {
|
||||
bold: bold,
|
||||
align: PosAlign.left,
|
||||
fontType: _font,
|
||||
height: _bodySize,
|
||||
height: _bodyHeight,
|
||||
width: _bodyWidth,
|
||||
),
|
||||
);
|
||||
@@ -72,7 +73,7 @@ class ReceiptComponentBuilder {
|
||||
bold: bold,
|
||||
align: PosAlign.right,
|
||||
fontType: _font,
|
||||
height: _bodySize,
|
||||
height: _bodyHeight,
|
||||
width: _bodyWidth,
|
||||
),
|
||||
);
|
||||
@@ -110,8 +111,6 @@ class ReceiptComponentBuilder {
|
||||
align: PosAlign.left,
|
||||
bold: bold,
|
||||
fontType: _font,
|
||||
height: _bodySize,
|
||||
width: _bodyWidth,
|
||||
),
|
||||
),
|
||||
PosColumn(
|
||||
@@ -121,8 +120,6 @@ class ReceiptComponentBuilder {
|
||||
align: PosAlign.right,
|
||||
bold: bold,
|
||||
fontType: _font,
|
||||
height: _bodySize,
|
||||
width: _bodyWidth,
|
||||
),
|
||||
),
|
||||
]);
|
||||
@@ -163,8 +160,8 @@ class ReceiptComponentBuilder {
|
||||
bold: bold,
|
||||
align: PosAlign.left,
|
||||
fontType: _font,
|
||||
height: PosTextSize.size2,
|
||||
width: PosTextSize.size2,
|
||||
height: _bodyHeight,
|
||||
width: _bodyWidth,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -184,7 +181,7 @@ class ReceiptComponentBuilder {
|
||||
required String phoneNumber,
|
||||
}) {
|
||||
List<int> bytes = [];
|
||||
bytes += textCenter(outletName, bold: true, height: _titleSize, width: _titleSize);
|
||||
bytes += textCenter(outletName, bold: true);
|
||||
bytes += textCenter(address);
|
||||
bytes += textCenter(phoneNumber);
|
||||
bytes += separator();
|
||||
@@ -193,7 +190,7 @@ class ReceiptComponentBuilder {
|
||||
|
||||
/// Centered printer type label (e.g. KITCHEN, BAR)
|
||||
List<int> printerType({required String printerType}) {
|
||||
return textCenter(printerType, bold: true, height: _titleSize, width: _titleSize);
|
||||
return textCenter(printerType, bold: true);
|
||||
}
|
||||
|
||||
/// Date + time row (receipt style)
|
||||
@@ -209,15 +206,21 @@ class ReceiptComponentBuilder {
|
||||
required String orderNumber,
|
||||
String? orderType,
|
||||
required String cashierName,
|
||||
String? customerName,
|
||||
}) {
|
||||
List<int> bytes = [];
|
||||
final dateStr = DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now());
|
||||
bytes += textLeft('Order : $orderNumber');
|
||||
bytes += textLeft('Date : $dateStr');
|
||||
if(orderType != null) {
|
||||
bytes += textLeft('Purpose : $orderType');
|
||||
bytes += textLeft('Order : $orderNumber');
|
||||
bytes += textLeft('Date : $dateStr');
|
||||
|
||||
|
||||
if(customerName != null) {
|
||||
bytes += textLeft('Customer : $customerName');
|
||||
}
|
||||
bytes += textLeft('Waiter : $cashierName');
|
||||
if(orderType != null) {
|
||||
bytes += textLeft('Purpose : ${orderType.toUpperCase()}');
|
||||
}
|
||||
bytes += textLeft('Waiter : $cashierName');
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@@ -250,7 +253,7 @@ class ReceiptComponentBuilder {
|
||||
List<int> orderType(String type) {
|
||||
List<int> bytes = [];
|
||||
bytes += separator();
|
||||
bytes += textCenter(type, bold: true, height: _titleSize, width: _titleSize);
|
||||
bytes += textCenter(type, bold: true);
|
||||
bytes += separator();
|
||||
return bytes;
|
||||
}
|
||||
@@ -268,8 +271,8 @@ class ReceiptComponentBuilder {
|
||||
final displayName = (variantName != null && variantName.isNotEmpty)
|
||||
? '$productName ($variantName)'
|
||||
: productName;
|
||||
bytes += textLeft(displayName, bold: paperSize == 80);
|
||||
bytes += row2Columns('$quantity x $unitPrice', totalPrice, leftWidth: 8, rightWidth: 4);
|
||||
bytes += textLeft(displayName, bold: true);
|
||||
bytes += row2Columns('${quantity}x $unitPrice', totalPrice);
|
||||
if (notes != null && notes.isNotEmpty) {
|
||||
bytes += row2Columns('Note', notes, leftWidth: 4, rightWidth: 8);
|
||||
}
|
||||
@@ -303,7 +306,7 @@ class ReceiptComponentBuilder {
|
||||
List<int> footer({String message = 'Terima kasih'}) {
|
||||
List<int> bytes = [];
|
||||
bytes += emptyLines(2);
|
||||
bytes += textCenter(message, bold: true, height: _titleSize, width: _titleSize);
|
||||
bytes += textCenter(message, bold: true);
|
||||
if (kDebugMode) {
|
||||
bytes += textCenter('$paperSize MM');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user