fix printer

This commit is contained in:
Efril 2026-05-27 19:51:43 +07:00
parent d345294a2f
commit 9a5f0c7415
3 changed files with 147 additions and 46 deletions

View File

@ -30,6 +30,9 @@ class PrintUi {
outletName: outlet.name,
address: outlet.address,
phoneNumber: outlet.phoneNumber,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.orderInfo(
@ -38,9 +41,14 @@ class PrintUi {
cashierName: cashierName,
paymentMethod: order.payments.last.paymentMethodName,
tableNumber: order.tableNumber,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.orderType(order.orderType);
bytes += builder.orderType(order.orderType, fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,);
bytes += builder.emptyLines(1);
@ -52,6 +60,9 @@ class PrintUi {
totalPrice: item.totalPrice.currencyFormatRpV2,
variantName: item.productVariantName,
notes: item.notes,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
}
@ -61,6 +72,9 @@ class PrintUi {
discount: order.discountAmount.currencyFormatRpV2,
total: order.totalAmount.currencyFormatRpV2,
paid: order.totalPaid.currencyFormatRpV2,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.footer();
@ -90,12 +104,7 @@ class PrintUi {
// Header
bytes += builder.textCenter('Table Checker', bold: true);
bytes += builder.separator();
bytes += builder.textCenter(
'Table : ${order.tableNumber.isNotEmpty ? order.tableNumber : '-'}',
bold: true,
);
bytes += builder.separator();
bytes += builder.tableName(order.tableNumber.isNotEmpty ? order.tableNumber : '-', height: PosTextSize.size3, width: PosTextSize.size3);
// Order info label : value, left aligned
bytes += builder.orderInfoSimple(
@ -301,6 +310,9 @@ class PrintUi {
outletName: outlet.name,
address: outlet.address,
phoneNumber: outlet.phoneNumber,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.orderInfo(
@ -311,9 +323,14 @@ class PrintUi {
? null
: order.payments.last.paymentMethodName,
tableNumber: order.tableNumber,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.orderType(order.orderType);
bytes += builder.orderType(order.orderType, fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,);
bytes += builder.emptyLines(1);
@ -325,6 +342,9 @@ class PrintUi {
totalPrice: item.totalPrice.currencyFormatRpV2,
variantName: item.productVariantName,
notes: item.notes,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
}
@ -334,6 +354,9 @@ class PrintUi {
discount: order.discountAmount.currencyFormatRpV2,
total: order.totalAmount.currencyFormatRpV2,
paid: order.totalPaid.currencyFormatRpV2,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.footer(message: 'Kasir');
@ -365,6 +388,9 @@ class PrintUi {
outletName: outlet.name,
address: outlet.address,
phoneNumber: outlet.phoneNumber,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.dateTime(DateTime.now());
@ -377,9 +403,14 @@ class PrintUi {
? null
: order.payments.last.paymentMethodName,
tableNumber: order.tableNumber,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.orderType('Void');
bytes += builder.orderType('Void', fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,);
bytes += builder.emptyLines(1);
@ -391,6 +422,9 @@ class PrintUi {
totalPrice: item.totalPrice.currencyFormatRpV2,
variantName: item.productVariantName,
notes: item.notes,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
}
bytes += builder.summary(
@ -399,6 +433,9 @@ class PrintUi {
discount: order.discountAmount.currencyFormatRpV2,
total: order.totalAmount.currencyFormatRpV2,
paid: order.totalPaid.currencyFormatRpV2,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.footer(message: 'Kasir');
@ -430,9 +467,14 @@ class PrintUi {
outletName: outlet.name,
address: outlet.address,
phoneNumber: outlet.phoneNumber,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.dateTime(DateTime.now());
bytes += builder.dateTime(DateTime.now(), fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,);
bytes += builder.orderInfo(
orderNumber: order.orderNumber,
@ -442,13 +484,21 @@ class PrintUi {
? null
: order.payments.last.paymentMethodName,
tableNumber: order.tableNumber,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.orderType('Split');
bytes += builder.orderType('Split', fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,);
bytes += builder.row2Columns(
'Split',
'${order.payments.last.splitNumber} / ${order.payments.last.splitTotal}',
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.separator();
@ -463,6 +513,9 @@ class PrintUi {
totalPrice: item.totalPrice.currencyFormatRpV2,
variantName: item.productVariantName,
notes: item.notes,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
}
@ -474,6 +527,9 @@ class PrintUi {
discount: 0.currencyFormatRpV2,
total: order.payments.last.amount.currencyFormatRpV2,
paid: order.payments.last.amount.currencyFormatRpV2,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
);
bytes += builder.footer(message: 'Terima Kasih');

View File

@ -53,28 +53,32 @@ class ReceiptComponentBuilder {
);
}
List<int> textLeft(String text, {bool bold = false}) {
List<int> textLeft(String text, {bool bold = false, PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,}) {
return generator.text(
text,
styles: PosStyles(
bold: bold,
align: PosAlign.left,
fontType: _font,
height: _bodyHeight,
width: _bodyWidth,
height: height ?? _bodyHeight,
width: width ?? _bodyWidth,
fontType: fontType ?? _font,
),
);
}
List<int> textRight(String text, {bool bold = false}) {
List<int> textRight(String text, {bool bold = false, PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,}) {
return generator.text(
text,
styles: PosStyles(
bold: bold,
align: PosAlign.right,
fontType: _font,
height: _bodyHeight,
width: _bodyWidth,
height: height ?? _bodyHeight,
width: width ?? _bodyWidth,
fontType: fontType ?? _font,
),
);
}
@ -102,6 +106,9 @@ class ReceiptComponentBuilder {
bool bold = false,
int leftWidth = 6,
int rightWidth = 6,
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) {
return generator.row([
PosColumn(
@ -110,9 +117,9 @@ class ReceiptComponentBuilder {
styles: PosStyles(
align: PosAlign.left,
bold: bold,
fontType: _font,
height: _bodyHeight,
width: _bodyWidth,
height: height ?? _bodyHeight,
width: width ?? _bodyWidth,
fontType: fontType ?? _font,
),
),
PosColumn(
@ -121,9 +128,9 @@ class ReceiptComponentBuilder {
styles: PosStyles(
align: PosAlign.right,
bold: bold,
fontType: _font,
height: _bodyHeight,
width: _bodyWidth,
height: height ?? _bodyHeight,
width: width ?? _bodyWidth,
fontType: fontType ?? _font,
),
),
]);
@ -183,14 +190,17 @@ class ReceiptComponentBuilder {
required String outletName,
required String address,
required String phoneNumber,
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) {
List<int> bytes = [];
bytes += textCenter(outletName, bold: true);
bytes += textCenter(address);
bytes += textCenter(phoneNumber);
bytes += textCenter(outletName, height: PosTextSize.size2, width: PosTextSize.size2, fontType: fontType, bold: true);
bytes += textCenter(address, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
bytes += textCenter(phoneNumber, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
bytes += separator();
return bytes;
}
}
/// Centered printer type label (e.g. KITCHEN, BAR)
List<int> printerType({required String printerType}) {
@ -198,10 +208,16 @@ class ReceiptComponentBuilder {
}
/// Date + time row (receipt style)
List<int> dateTime(DateTime dateTime) {
List<int> dateTime(DateTime dateTime, { PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) {
return row2Columns(
DateFormat('dd MMM yyyy').format(dateTime),
DateFormat('HH:mm').format(dateTime),
height: height ?? _bodyHeight,
width: width ?? _bodyWidth,
fontType: fontType ?? _font,
);
}
@ -235,29 +251,48 @@ class ReceiptComponentBuilder {
required String cashierName,
String? paymentMethod,
String? tableNumber,
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) {
List<int> bytes = [];
final dateStr = DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now());
bytes += textLeft('Order : $orderNumber');
bytes += textLeft('Date : $dateStr');
bytes += textLeft('Order : $orderNumber', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
bytes += textLeft('Date : $dateStr', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
if (tableNumber != null && tableNumber.isNotEmpty) {
bytes += textLeft('Table : $tableNumber');
bytes += textLeft('Table : $tableNumber', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
}
bytes += textLeft('Waiter : $cashierName');
bytes += textLeft('Customer : $customerName');
bytes += textLeft('Waiter : $cashierName', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
bytes += textLeft('Customer : $customerName', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
if (paymentMethod != null) {
bytes += textLeft('Payment : $paymentMethod');
bytes += textLeft('Payment : $paymentMethod', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
}
return bytes;
}
/// Order type banner (separator + type + separator)
List<int> orderType(String type) {
List<int> orderType(String type, {
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) {
List<int> bytes = [];
bytes += separator();
bytes += textCenter(type, bold: true);
bytes += textCenter(type.toUpperCase(), fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth, bold: true);
bytes += separator();
return bytes;
}
List<int> tableName(String table, {
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) {
List<int> bytes = [];
bytes += separator();
bytes += textCenter( 'Table : ${table.isNotEmpty ? table : '-'}', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth, bold: true);
bytes += separator();
return bytes;
}
@ -270,15 +305,18 @@ class ReceiptComponentBuilder {
required String totalPrice,
String? variantName,
String? notes,
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) {
List<int> bytes = [];
final displayName = (variantName != null && variantName.isNotEmpty)
? '$productName ($variantName)'
: productName;
bytes += textLeft(displayName, bold: true);
bytes += row2Columns('${quantity}x $unitPrice', totalPrice);
bytes += textLeft(displayName, bold: true, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
bytes += row2Columns('${quantity}x $unitPrice', totalPrice, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
if (notes != null && notes.isNotEmpty) {
bytes += row2Columns('Note', notes, leftWidth: 4, rightWidth: 8);
bytes += row2Columns('Note', notes, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth, leftWidth: 4, rightWidth: 8);
}
bytes += emptyLines(1);
return bytes;
@ -291,17 +329,20 @@ class ReceiptComponentBuilder {
required String discount,
required String total,
required String paid,
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) {
List<int> bytes = [];
bytes += separator();
if (totalItems > 0) {
bytes += row2Columns('Total Item', totalItems.toString());
bytes += row2Columns('Total Item', totalItems.toString(), fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
}
bytes += row2Columns('Subtotal', subtotal);
bytes += row2Columns('Diskon', discount);
bytes += row2Columns('Subtotal', subtotal, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
bytes += row2Columns('Diskon', discount, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
bytes += separator();
bytes += row2Columns('Total', total, bold: true);
bytes += row2Columns('Bayar', paid);
bytes += row2Columns('Total', total, bold: true, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
bytes += row2Columns('Bayar', paid, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
bytes += separator();
return bytes;
}

View File

@ -32,6 +32,8 @@ class SettingPrinterForm extends StatefulWidget {
class _SettingPrinterFormState extends State<SettingPrinterForm> {
final TextEditingController _nameController = TextEditingController();
final TextEditingController _networkController = TextEditingController();
void setup() {
if (widget.printer != null) {
context.read<PrinterFormBloc>().add(
@ -50,6 +52,7 @@ class _SettingPrinterFormState extends State<SettingPrinterForm> {
PrinterFormEvent.paperChanged(widget.printer!.paper),
);
_nameController.text = widget.printer!.name;
_networkController.text = widget.printer!.address;
}
}
@ -163,6 +166,7 @@ class _SettingPrinterFormState extends State<SettingPrinterForm> {
)
: AppTextFormField(
label: 'Network',
controller: _networkController,
onChanged: (value) {
context.read<PrinterFormBloc>().add(
PrinterFormEvent.addressChanged(value),