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, outletName: outlet.name,
address: outlet.address, address: outlet.address,
phoneNumber: outlet.phoneNumber, phoneNumber: outlet.phoneNumber,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
); );
bytes += builder.orderInfo( bytes += builder.orderInfo(
@ -38,9 +41,14 @@ class PrintUi {
cashierName: cashierName, cashierName: cashierName,
paymentMethod: order.payments.last.paymentMethodName, paymentMethod: order.payments.last.paymentMethodName,
tableNumber: order.tableNumber, 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); bytes += builder.emptyLines(1);
@ -52,6 +60,9 @@ class PrintUi {
totalPrice: item.totalPrice.currencyFormatRpV2, totalPrice: item.totalPrice.currencyFormatRpV2,
variantName: item.productVariantName, variantName: item.productVariantName,
notes: item.notes, notes: item.notes,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
); );
} }
@ -61,6 +72,9 @@ class PrintUi {
discount: order.discountAmount.currencyFormatRpV2, discount: order.discountAmount.currencyFormatRpV2,
total: order.totalAmount.currencyFormatRpV2, total: order.totalAmount.currencyFormatRpV2,
paid: order.totalPaid.currencyFormatRpV2, paid: order.totalPaid.currencyFormatRpV2,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
); );
bytes += builder.footer(); bytes += builder.footer();
@ -90,12 +104,7 @@ class PrintUi {
// Header // Header
bytes += builder.textCenter('Table Checker', bold: true); bytes += builder.textCenter('Table Checker', bold: true);
bytes += builder.separator(); bytes += builder.tableName(order.tableNumber.isNotEmpty ? order.tableNumber : '-', height: PosTextSize.size3, width: PosTextSize.size3);
bytes += builder.textCenter(
'Table : ${order.tableNumber.isNotEmpty ? order.tableNumber : '-'}',
bold: true,
);
bytes += builder.separator();
// Order info label : value, left aligned // Order info label : value, left aligned
bytes += builder.orderInfoSimple( bytes += builder.orderInfoSimple(
@ -301,6 +310,9 @@ class PrintUi {
outletName: outlet.name, outletName: outlet.name,
address: outlet.address, address: outlet.address,
phoneNumber: outlet.phoneNumber, phoneNumber: outlet.phoneNumber,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
); );
bytes += builder.orderInfo( bytes += builder.orderInfo(
@ -311,9 +323,14 @@ class PrintUi {
? null ? null
: order.payments.last.paymentMethodName, : order.payments.last.paymentMethodName,
tableNumber: order.tableNumber, 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); bytes += builder.emptyLines(1);
@ -325,6 +342,9 @@ class PrintUi {
totalPrice: item.totalPrice.currencyFormatRpV2, totalPrice: item.totalPrice.currencyFormatRpV2,
variantName: item.productVariantName, variantName: item.productVariantName,
notes: item.notes, notes: item.notes,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
); );
} }
@ -334,6 +354,9 @@ class PrintUi {
discount: order.discountAmount.currencyFormatRpV2, discount: order.discountAmount.currencyFormatRpV2,
total: order.totalAmount.currencyFormatRpV2, total: order.totalAmount.currencyFormatRpV2,
paid: order.totalPaid.currencyFormatRpV2, paid: order.totalPaid.currencyFormatRpV2,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
); );
bytes += builder.footer(message: 'Kasir'); bytes += builder.footer(message: 'Kasir');
@ -365,6 +388,9 @@ class PrintUi {
outletName: outlet.name, outletName: outlet.name,
address: outlet.address, address: outlet.address,
phoneNumber: outlet.phoneNumber, phoneNumber: outlet.phoneNumber,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
); );
bytes += builder.dateTime(DateTime.now()); bytes += builder.dateTime(DateTime.now());
@ -377,9 +403,14 @@ class PrintUi {
? null ? null
: order.payments.last.paymentMethodName, : order.payments.last.paymentMethodName,
tableNumber: order.tableNumber, 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); bytes += builder.emptyLines(1);
@ -391,6 +422,9 @@ class PrintUi {
totalPrice: item.totalPrice.currencyFormatRpV2, totalPrice: item.totalPrice.currencyFormatRpV2,
variantName: item.productVariantName, variantName: item.productVariantName,
notes: item.notes, notes: item.notes,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
); );
} }
bytes += builder.summary( bytes += builder.summary(
@ -399,6 +433,9 @@ class PrintUi {
discount: order.discountAmount.currencyFormatRpV2, discount: order.discountAmount.currencyFormatRpV2,
total: order.totalAmount.currencyFormatRpV2, total: order.totalAmount.currencyFormatRpV2,
paid: order.totalPaid.currencyFormatRpV2, paid: order.totalPaid.currencyFormatRpV2,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
); );
bytes += builder.footer(message: 'Kasir'); bytes += builder.footer(message: 'Kasir');
@ -430,9 +467,14 @@ class PrintUi {
outletName: outlet.name, outletName: outlet.name,
address: outlet.address, address: outlet.address,
phoneNumber: outlet.phoneNumber, 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( bytes += builder.orderInfo(
orderNumber: order.orderNumber, orderNumber: order.orderNumber,
@ -442,13 +484,21 @@ class PrintUi {
? null ? null
: order.payments.last.paymentMethodName, : order.payments.last.paymentMethodName,
tableNumber: order.tableNumber, 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( bytes += builder.row2Columns(
'Split', 'Split',
'${order.payments.last.splitNumber} / ${order.payments.last.splitTotal}', '${order.payments.last.splitNumber} / ${order.payments.last.splitTotal}',
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
); );
bytes += builder.separator(); bytes += builder.separator();
@ -463,6 +513,9 @@ class PrintUi {
totalPrice: item.totalPrice.currencyFormatRpV2, totalPrice: item.totalPrice.currencyFormatRpV2,
variantName: item.productVariantName, variantName: item.productVariantName,
notes: item.notes, notes: item.notes,
fontType: PosFontType.fontA,
width: PosTextSize.size1,
height: PosTextSize.size1,
); );
} }
@ -474,6 +527,9 @@ class PrintUi {
discount: 0.currencyFormatRpV2, discount: 0.currencyFormatRpV2,
total: order.payments.last.amount.currencyFormatRpV2, total: order.payments.last.amount.currencyFormatRpV2,
paid: 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'); 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( return generator.text(
text, text,
styles: PosStyles( styles: PosStyles(
bold: bold, bold: bold,
align: PosAlign.left, align: PosAlign.left,
fontType: _font, height: height ?? _bodyHeight,
height: _bodyHeight, width: width ?? _bodyWidth,
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( return generator.text(
text, text,
styles: PosStyles( styles: PosStyles(
bold: bold, bold: bold,
align: PosAlign.right, align: PosAlign.right,
fontType: _font, height: height ?? _bodyHeight,
height: _bodyHeight, width: width ?? _bodyWidth,
width: _bodyWidth, fontType: fontType ?? _font,
), ),
); );
} }
@ -102,6 +106,9 @@ class ReceiptComponentBuilder {
bool bold = false, bool bold = false,
int leftWidth = 6, int leftWidth = 6,
int rightWidth = 6, int rightWidth = 6,
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) { }) {
return generator.row([ return generator.row([
PosColumn( PosColumn(
@ -110,9 +117,9 @@ class ReceiptComponentBuilder {
styles: PosStyles( styles: PosStyles(
align: PosAlign.left, align: PosAlign.left,
bold: bold, bold: bold,
fontType: _font, height: height ?? _bodyHeight,
height: _bodyHeight, width: width ?? _bodyWidth,
width: _bodyWidth, fontType: fontType ?? _font,
), ),
), ),
PosColumn( PosColumn(
@ -121,9 +128,9 @@ class ReceiptComponentBuilder {
styles: PosStyles( styles: PosStyles(
align: PosAlign.right, align: PosAlign.right,
bold: bold, bold: bold,
fontType: _font, height: height ?? _bodyHeight,
height: _bodyHeight, width: width ?? _bodyWidth,
width: _bodyWidth, fontType: fontType ?? _font,
), ),
), ),
]); ]);
@ -183,11 +190,14 @@ class ReceiptComponentBuilder {
required String outletName, required String outletName,
required String address, required String address,
required String phoneNumber, required String phoneNumber,
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) { }) {
List<int> bytes = []; List<int> bytes = [];
bytes += textCenter(outletName, bold: true); bytes += textCenter(outletName, height: PosTextSize.size2, width: PosTextSize.size2, fontType: fontType, bold: true);
bytes += textCenter(address); bytes += textCenter(address, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
bytes += textCenter(phoneNumber); bytes += textCenter(phoneNumber, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
bytes += separator(); bytes += separator();
return bytes; return bytes;
} }
@ -198,10 +208,16 @@ class ReceiptComponentBuilder {
} }
/// Date + time row (receipt style) /// Date + time row (receipt style)
List<int> dateTime(DateTime dateTime) { List<int> dateTime(DateTime dateTime, { PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) {
return row2Columns( return row2Columns(
DateFormat('dd MMM yyyy').format(dateTime), DateFormat('dd MMM yyyy').format(dateTime),
DateFormat('HH:mm').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, required String cashierName,
String? paymentMethod, String? paymentMethod,
String? tableNumber, String? tableNumber,
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) { }) {
List<int> bytes = []; List<int> bytes = [];
final dateStr = DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now()); final dateStr = DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now());
bytes += textLeft('Order : $orderNumber'); bytes += textLeft('Order : $orderNumber', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
bytes += textLeft('Date : $dateStr'); bytes += textLeft('Date : $dateStr', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
if (tableNumber != null && tableNumber.isNotEmpty) { 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('Waiter : $cashierName', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
bytes += textLeft('Customer : $customerName'); bytes += textLeft('Customer : $customerName', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
if (paymentMethod != null) { if (paymentMethod != null) {
bytes += textLeft('Payment : $paymentMethod'); bytes += textLeft('Payment : $paymentMethod', fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
} }
return bytes; return bytes;
} }
/// Order type banner (separator + type + separator) /// 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 = []; List<int> bytes = [];
bytes += separator(); 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(); bytes += separator();
return bytes; return bytes;
} }
@ -270,15 +305,18 @@ class ReceiptComponentBuilder {
required String totalPrice, required String totalPrice,
String? variantName, String? variantName,
String? notes, String? notes,
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) { }) {
List<int> bytes = []; List<int> bytes = [];
final displayName = (variantName != null && variantName.isNotEmpty) final displayName = (variantName != null && variantName.isNotEmpty)
? '$productName ($variantName)' ? '$productName ($variantName)'
: productName; : productName;
bytes += textLeft(displayName, bold: true); bytes += textLeft(displayName, bold: true, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth);
bytes += row2Columns('${quantity}x $unitPrice', totalPrice); bytes += row2Columns('${quantity}x $unitPrice', totalPrice, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
if (notes != null && notes.isNotEmpty) { 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); bytes += emptyLines(1);
return bytes; return bytes;
@ -291,17 +329,20 @@ class ReceiptComponentBuilder {
required String discount, required String discount,
required String total, required String total,
required String paid, required String paid,
PosTextSize? height,
PosTextSize? width,
PosFontType? fontType,
}) { }) {
List<int> bytes = []; List<int> bytes = [];
bytes += separator(); bytes += separator();
if (totalItems > 0) { 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('Subtotal', subtotal, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
bytes += row2Columns('Diskon', discount); bytes += row2Columns('Diskon', discount, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
bytes += separator(); bytes += separator();
bytes += row2Columns('Total', total, bold: true); bytes += row2Columns('Total', total, bold: true, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
bytes += row2Columns('Bayar', paid); bytes += row2Columns('Bayar', paid, fontType: fontType, height: height ?? _bodyHeight, width: width ?? _bodyWidth,);
bytes += separator(); bytes += separator();
return bytes; return bytes;
} }

View File

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