From 9a5f0c7415203042c4c3ad229dfecd8c735ed526 Mon Sep 17 00:00:00 2001 From: Efril Date: Wed, 27 May 2026 19:51:43 +0700 Subject: [PATCH] fix printer --- .../components/print/print_ui.dart | 78 ++++++++++-- .../print/receipt_component_builder.dart | 111 ++++++++++++------ .../printer/setting_printer_form.dart | 4 + 3 files changed, 147 insertions(+), 46 deletions(-) diff --git a/lib/presentation/components/print/print_ui.dart b/lib/presentation/components/print/print_ui.dart index af6b340..dcd8985 100644 --- a/lib/presentation/components/print/print_ui.dart +++ b/lib/presentation/components/print/print_ui.dart @@ -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'); diff --git a/lib/presentation/components/print/receipt_component_builder.dart b/lib/presentation/components/print/receipt_component_builder.dart index 4e402d2..a0f3081 100644 --- a/lib/presentation/components/print/receipt_component_builder.dart +++ b/lib/presentation/components/print/receipt_component_builder.dart @@ -53,28 +53,32 @@ class ReceiptComponentBuilder { ); } - List textLeft(String text, {bool bold = false}) { + List 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 textRight(String text, {bool bold = false}) { + List 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 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 printerType({required String printerType}) { @@ -198,10 +208,16 @@ class ReceiptComponentBuilder { } /// Date + time row (receipt style) - List dateTime(DateTime dateTime) { + List 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 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 orderType(String type) { + List orderType(String type, { + PosTextSize? height, + PosTextSize? width, + PosFontType? fontType, + }) { List 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 tableName(String table, { + PosTextSize? height, + PosTextSize? width, + PosFontType? fontType, + }) { + List 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 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 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; } diff --git a/lib/presentation/pages/main/pages/setting/sections/printer/setting_printer_form.dart b/lib/presentation/pages/main/pages/setting/sections/printer/setting_printer_form.dart index 5ad248e..965e083 100644 --- a/lib/presentation/pages/main/pages/setting/sections/printer/setting_printer_form.dart +++ b/lib/presentation/pages/main/pages/setting/sections/printer/setting_printer_form.dart @@ -32,6 +32,8 @@ class SettingPrinterForm extends StatefulWidget { class _SettingPrinterFormState extends State { final TextEditingController _nameController = TextEditingController(); + final TextEditingController _networkController = TextEditingController(); + void setup() { if (widget.printer != null) { context.read().add( @@ -50,6 +52,7 @@ class _SettingPrinterFormState extends State { PrinterFormEvent.paperChanged(widget.printer!.paper), ); _nameController.text = widget.printer!.name; + _networkController.text = widget.printer!.address; } } @@ -163,6 +166,7 @@ class _SettingPrinterFormState extends State { ) : AppTextFormField( label: 'Network', + controller: _networkController, onChanged: (value) { context.read().add( PrinterFormEvent.addressChanged(value),