update latest

This commit is contained in:
Tothemax Dev
2024-09-27 16:15:19 +07:00
parent 5419429426
commit 88c298cc79
9 changed files with 329 additions and 575 deletions

View File

@@ -1,6 +1,7 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:max_print_plus/max_print_plus.dart';
import 'package:max_print_plus/print/max_print.dart';
void main() {
@@ -53,8 +54,7 @@ class _MyHomePageState extends State<MyHomePage> {
child: Text('Click me')),
ElevatedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => MaxPrint()));
_printReceiveTest(true);
},
child: Text('Print page mode')),
],
@@ -63,220 +63,210 @@ class _MyHomePageState extends State<MyHomePage> {
));
}
// Future _printReceiveTest(bool isPage) async {
// List<int> bytes = [];
Future _printReceiveTest(bool isPage) async {
List<int> bytes = [];
// // Xprinter XP-N160I
// final profile = await CapabilityProfile.load(name: 'XP-N160I');
// Xprinter XP-N160I
final profile = await CapabilityProfile.load(name: 'XP-N160I');
// // PaperSize.mm80 or PaperSize.mm58
// final generator = Generator(PaperSize.mm58, profile);
// bytes += generator.setGlobalCodeTable('CP1252');
// bytes += generator.text('MM TOYS',
// styles: const PosStyles(align: PosAlign.center, bold: true));
// PaperSize.mm80 or PaperSize.mm58
final generator =
EscGenerator(PaperSizeWidth.mm58, PaperSizeMaxPerLine.mm58, profile);
bytes += generator.setGlobalCodeTable('CP1252');
bytes += generator.text('MM TOYS',
styles: const PosStyles(align: PosAlign.center, bold: true));
// bytes += generator.text('Cikijing, Talaga, Bantarujeg, Rancah',
// styles: const PosStyles(align: PosAlign.center, bold: true));
bytes += generator.text('Cikijing, Talaga, Bantarujeg, Rancah',
styles: const PosStyles(align: PosAlign.center, bold: true));
// bytes += generator.row([
// PosColumn(
// width: 6,
// text: 'PENJUALAN :',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// PosColumn(
// width: 6,
// text: '2024-03-14',
// styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// ]);
bytes += generator.row([
PosColumn(
width: 6,
text: 'PENJUALAN :',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
PosColumn(
width: 6,
text: '2024-03-14',
styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
]);
// bytes += generator.row([
// PosColumn(
// width: 8,
// text: 'PELANGGAN : UMUM-RCH',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// PosColumn(
// width: 4,
// text: '15:30',
// styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// ]);
bytes += generator.row([
PosColumn(
width: 8,
text: 'PELANGGAN : UMUM-RCH',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
PosColumn(
width: 4,
text: '15:30',
styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
]);
// bytes += generator.text('--------------------------------',
// styles: const PosStyles(align: PosAlign.center));
// bytes += generator.row([
// PosColumn(
// width: 6,
// text: 'Qty',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// PosColumn(
// width: 6,
// text: 'Nama Produk',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// ]);
bytes += generator.text('--------------------------------',
styles: const PosStyles(align: PosAlign.center));
bytes += generator.row([
PosColumn(
width: 6,
text: 'Qty',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
PosColumn(
width: 6,
text: 'Nama Produk',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
]);
// bytes += generator.row([
// PosColumn(
// width: 3,
// text: 'Harga',
// styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// PosColumn(
// width: 3,
// text: 'Dis.',
// styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// PosColumn(
// width: 3,
// text: 'PPn',
// styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// PosColumn(
// width: 3,
// text: 'Netto',
// styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// ]);
bytes += generator.row([
PosColumn(
width: 3,
text: 'Harga',
styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
PosColumn(
width: 3,
text: 'Dis.',
styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
PosColumn(
width: 3,
text: 'PPn',
styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
PosColumn(
width: 3,
text: 'Netto',
styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
]);
// bytes += generator.text('--------------------------------',
// styles: const PosStyles(align: PosAlign.center));
bytes += generator.text('--------------------------------',
styles: const PosStyles(align: PosAlign.center));
// // Dummy transaction data
// List<String> dummyProducts = [
// 'Product 1',
// 'Product 2',
// 'Product 3',
// ];
// Dummy transaction data
List<String> dummyProducts = [
'Product 1',
'Product 2',
'Product 3',
];
// for (var productName in dummyProducts) {
// bytes += generator.row([
// PosColumn(
// width: 12,
// text: '2 ${productName.toUpperCase()}',
// styles: const PosStyles(
// align: PosAlign.left,
// codeTable: 'CP1252',
// )),
// ]);
for (var productName in dummyProducts) {
bytes += generator.row([
PosColumn(
width: 12,
text: '2 ${productName.toUpperCase()}',
styles: const PosStyles(
align: PosAlign.left,
codeTable: 'CP1252',
)),
]);
// bytes += generator.row([
// PosColumn(
// width: 3,
// text: '10.0',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// PosColumn(
// width: 3,
// text: '0.0',
// styles:
// const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// PosColumn(
// width: 3,
// text: '',
// styles:
// const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// PosColumn(
// width: 3,
// text: '20.0',
// styles:
// const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// ]);
// }
bytes += generator.row([
PosColumn(
width: 3,
text: '10.0',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
PosColumn(
width: 3,
text: '0.0',
styles:
const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
PosColumn(
width: 3,
text: '',
styles:
const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
PosColumn(
width: 3,
text: '20.0',
styles:
const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
]);
}
// bytes += generator.text('--------------------------------',
// styles: const PosStyles(align: PosAlign.center));
bytes += generator.text('--------------------------------',
styles: const PosStyles(align: PosAlign.center));
// // Dummy total and payment data
// bytes += generator.row([
// PosColumn(
// width: 4,
// text: 'Jumlah : 3',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// PosColumn(
// width: 4,
// text: 'Item : 6',
// styles: const PosStyles(align: PosAlign.center, codeTable: 'CP1252')),
// PosColumn(
// width: 4,
// text: '33.0',
// styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// ]);
// Dummy total and payment data
bytes += generator.row([
PosColumn(
width: 4,
text: 'Jumlah : 3',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
PosColumn(
width: 4,
text: 'Item : 6',
styles: const PosStyles(align: PosAlign.center, codeTable: 'CP1252')),
PosColumn(
width: 4,
text: '33.0',
styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
]);
// // Dummy grand total, payment, change, and cashier data
// bytes += generator.row([
// PosColumn(
// width: 6,
// text: 'Grand Total',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// PosColumn(
// width: 1,
// text: ':',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// PosColumn(
// width: 5,
// text: '33.0',
// styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// ]);
// bytes += generator.row([
// PosColumn(
// width: 6,
// text: 'Pembayaran',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// PosColumn(
// width: 1,
// text: ':',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// PosColumn(
// width: 5,
// text: '50.0',
// styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// ]);
// bytes += generator.row([
// PosColumn(
// width: 6,
// text: 'Kembalian',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// PosColumn(
// width: 1,
// text: ':',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// PosColumn(
// width: 5,
// text: '17.0',
// styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// ]);
// bytes += generator.row([
// PosColumn(
// width: 6,
// text: 'Kasir',
// styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
// PosColumn(
// width: 6,
// text: 'Anisa',
// styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
// ]);
// Dummy grand total, payment, change, and cashier data
bytes += generator.row([
PosColumn(
width: 6,
text: 'Grand Total',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
PosColumn(
width: 1,
text: ':',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
PosColumn(
width: 5,
text: '33.0',
styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
]);
bytes += generator.row([
PosColumn(
width: 6,
text: 'Pembayaran',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
PosColumn(
width: 1,
text: ':',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
PosColumn(
width: 5,
text: '50.0',
styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
]);
bytes += generator.row([
PosColumn(
width: 6,
text: 'Kembalian',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
PosColumn(
width: 1,
text: ':',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
PosColumn(
width: 5,
text: '17.0',
styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
]);
bytes += generator.row([
PosColumn(
width: 6,
text: 'Kasir',
styles: const PosStyles(align: PosAlign.left, codeTable: 'CP1252')),
PosColumn(
width: 6,
text: 'Anisa',
styles: const PosStyles(align: PosAlign.right, codeTable: 'CP1252')),
]);
// bytes += generator.text('--------------------------------',
// styles: const PosStyles(align: PosAlign.center));
bytes += generator.text('--------------------------------',
styles: const PosStyles(align: PosAlign.center));
// bytes += generator.text(
// 'BARANG YANG SUDAH DI BELI TIDAK DAPAT DITUKAR / DIKEMBALIKAN',
// styles: const PosStyles(align: PosAlign.center));
// bytes += generator.text('TERIMA KASIH',
// styles: const PosStyles(align: PosAlign.center));
bytes += generator.text(
'BARANG YANG SUDAH DI BELI TIDAK DAPAT DITUKAR / DIKEMBALIKAN',
styles: const PosStyles(align: PosAlign.center));
bytes += generator.text('TERIMA KASIH',
styles: const PosStyles(align: PosAlign.center));
// if (isPage == false) {
// _showPrintDialog(bytes, generator);
// } else {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => MaxPrintPage(
// bytes: bytes,
// generator: generator,
// title: 'Test',
// description: 'Test',
// onSuccess: () {
// Navigator.pop(context);
// log('Printed');
// },
// appBar: null,
// )));
// }
// }
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MaxPrint(
bytes: bytes,
generator: generator,
)));
}
// _showPrintDialog(List<int> bytes, Generator generator) {
// return showDialog(