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(

View File

@@ -105,22 +105,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.10"
dio:
dependency: transitive
description:
name: dio
sha256: "5598aa796bbf4699afd5c67c0f5f6e2ed542afc956884b9cd58c306966efc260"
url: "https://pub.dev"
source: hosted
version: "5.7.0"
dio_web_adapter:
dependency: transitive
description:
name: dio_web_adapter
sha256: "33259a9276d6cea88774a0000cfae0d861003497755969c92faa223108620dc8"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
drago_blue_printer:
dependency: transitive
description:
@@ -145,14 +129,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.1.0"
easy_logger:
dependency: transitive
description:
name: easy_logger
sha256: c764a6e024846f33405a2342caf91c62e357c24b02c04dbc712ef232bf30ffb7
url: "https://pub.dev"
source: hosted
version: "0.0.2"
fake_async:
dependency: transitive
description:
@@ -279,14 +255,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
leak_tracker:
dependency: transitive
description:
@@ -319,14 +287,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.0"
logging:
dependency: transitive
description:
name: logging
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
matcher:
dependency: transitive
description:
@@ -542,14 +502,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.8"
pool:
dependency: transitive
description:
name: pool
sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a"
url: "https://pub.dev"
source: hosted
version: "1.5.1"
printing:
dependency: transitive
description:
@@ -566,14 +518,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.0.2"
puppeteer:
dependency: transitive
description:
name: puppeteer
sha256: fc33b2a12731e0b9e16c40cd91ea2b6886bcc24037a435fceb59b786d4074f2b
url: "https://pub.dev"
source: hosted
version: "3.15.0"
qr:
dependency: transitive
description:
@@ -743,10 +687,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "14.2.5"
web:
dependency: transitive
description:
@@ -755,14 +699,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
webcontent_converter:
dependency: transitive
description:
name: webcontent_converter
sha256: dab8a6abda92eb83e168d92a66f1b174f7e8c317351e6cc868440a1c1343d5f5
url: "https://pub.dev"
source: hosted
version: "0.0.9+2"
webdriver:
dependency: transitive
description:

View File

@@ -0,0 +1,22 @@
export 'package:drago_pos_printer/models/network_printer.dart';
export 'package:drago_pos_printer/models/bluetooth_printer.dart';
export 'package:drago_pos_printer/models/usb_printer.dart';
export 'package:drago_pos_printer/services/bluetooth_printer_manager_web.dart'
if (dart.library.js) 'package:drago_pos_printer/services/bluetooth_printer_manager_web.dart'
if (dart.library.io) 'package:drago_pos_printer/services/bluetooth_printer_manager.dart';
export 'package:drago_pos_printer/services/network_printer_manager.dart';
export 'package:drago_pos_printer/services/usb_printer_manager_web.dart'
if (dart.library.js) 'package:drago_pos_printer/services/usb_printer_manager_web.dart'
if (dart.library.io) 'package:drago_pos_printer/services/usb_printer_manager.dart';
export 'package:drago_pos_printer/enums/bluetooth_printer_type.dart';
export 'package:drago_pos_printer/enums/connection_response.dart';
export 'package:drago_pos_printer/enums/connection_type.dart';
export 'package:drago_pos_printer/utils/esc_pos_utils.dart';
export 'package:drago_pos_printer/utils/tsc_utils.dart';
export 'package:max_print_plus/print/max_print.dart';
class DragoPrinterManager {}

View File

@@ -1,11 +1,17 @@
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:drago_pos_printer/drago_pos_printer.dart';
import 'package:webcontent_converter/demo.dart';
import 'package:webcontent_converter/webcontent_converter.dart';
// import 'package:webcontent_converter/demo.dart';
// import 'package:webcontent_converter/webcontent_converter.dart';
import '../service/service.dart';
class BluetoothPrinterScreen extends StatefulWidget {
List<int> bytes;
EscGenerator generator;
BluetoothPrinterScreen(
{super.key, required this.bytes, required this.generator});
@override
_BluetoothPrinterScreenState createState() => _BluetoothPrinterScreenState();
}
@@ -37,9 +43,7 @@ class _BluetoothPrinterScreenState extends State<BluetoothPrinterScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Bluetooth Printer Screen"),
),
backgroundColor: Color(0xFFFAFAFA),
body: ListView(
padding: EdgeInsets.all(20),
children: [
@@ -164,27 +168,29 @@ class _BluetoothPrinterScreenState extends State<BluetoothPrinterScreen> {
late List<int> data;
if (byteType == 1) {
data = await ESCPrinterService(null).getSamplePosBytes(
paperSizeWidthMM: paperWidth,
maxPerLine: charPerLine,
profile: profile);
paperSizeWidthMM: paperWidth,
maxPerLine: charPerLine,
profile: profile,
bytesData: widget.bytes,
);
} else if (byteType == 2) {
data = await ESCPrinterService(null).getPdfBytes(
paperSizeWidthMM: paperWidth,
maxPerLine: charPerLine,
profile: profile);
} else if (byteType == 3) {
final content = Demo.getShortReceiptContent();
// final content = Demo.getShortReceiptContent();
Uint8List? htmlBytes = await WebcontentConverter.contentToImage(
content: content,
executablePath: WebViewHelper.executablePath(),
);
// Uint8List? htmlBytes = await WebcontentConverter.contentToImage(
// content: content,
// executablePath: WebViewHelper.executablePath(),
// );
var service = ESCPrinterService(htmlBytes);
data = await service.getBytes(
paperSizeWidthMM: paperWidth,
maxPerLine: charPerLine,
profile: profile);
// var service = ESCPrinterService(htmlBytes);
// data = await service.getBytes(
// paperSizeWidthMM: paperWidth,
// maxPerLine: charPerLine,
// profile: profile);
}
if (_manager != null) {

View File

@@ -1,3 +1,4 @@
import 'package:drago_pos_printer/utils/esc_pos/generator.dart';
import 'package:flutter/material.dart';
import 'package:max_print_plus/print/bluetooth_printer_screen.dart';
import 'package:max_print_plus/print/network_printer_screen.dart';
@@ -7,37 +8,11 @@ import 'tab_bar.dart';
enum HistoryTabData { reservation, dinein, waitinglist, pickup, delivery }
class MaxPrintArgs {
final int _index = 0;
HistoryTabData initialTab;
MaxPrintArgs({required this.initialTab});
int get initialIndex => mapTabDataToIndex();
int mapTabDataToIndex() {
switch (initialTab) {
case HistoryTabData.reservation:
return 0;
case HistoryTabData.dinein:
return 1;
case HistoryTabData.waitinglist:
return 2;
case HistoryTabData.pickup:
return 3;
case HistoryTabData.delivery:
return 4;
default:
return 0;
}
}
}
class MaxPrint extends StatefulWidget {
MaxPrint({
Key? key,
}) : super(key: key);
List<int> bytes;
EscGenerator generator;
MaxPrint({Key? key, required this.bytes, required this.generator})
: super(key: key);
@override
State<MaxPrint> createState() => _MaxPrintState();
@@ -71,7 +46,15 @@ class _MaxPrintState extends State<MaxPrint> with TickerProviderStateMixin {
child: Scaffold(
backgroundColor: Color(0xFFFAFAFA),
appBar: AppBar(
title: Text('Print'),
backgroundColor: Color(0xFFFAFAFA),
centerTitle: true,
title: const Text(
'Print',
style: TextStyle(
fontWeight: FontWeight.bold,
// letterSpacing: 2.0,
fontSize: 16),
),
bottom: CustomTabBar(
tabController: _tabController,
tabs: [
@@ -89,7 +72,8 @@ class _MaxPrintState extends State<MaxPrint> with TickerProviderStateMixin {
child: TabBarView(
controller: _tabController,
children: [
BluetoothPrinterScreen(),
BluetoothPrinterScreen(
bytes: widget.bytes, generator: widget.generator),
NetWorkPrinterScreen(),
USBPrinterScreen()
],

View File

@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:drago_pos_printer/drago_pos_printer.dart';
import 'package:webcontent_converter/demo.dart';
import 'package:webcontent_converter/webcontent_converter.dart';
// import 'package:webcontent_converter/demo.dart';
// import 'package:webcontent_converter/webcontent_converter.dart';
import '../service/service.dart';
@@ -40,6 +40,7 @@ class _NetWorkPrinterScreenState extends State<NetWorkPrinterScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFFFAFAFA),
appBar: AppBar(
title: Text("Network Printer Screen ${printProfiles.length}"),
actions: [
@@ -177,7 +178,7 @@ class _NetWorkPrinterScreenState extends State<NetWorkPrinterScreen> {
_startPrinter(int byteType, NetWorkPrinter printer) async {
await _connect(printer);
// if (_data.isEmpty) {
final content = Demo.getShortReceiptContent();
// final content = Demo.getShortReceiptContent();
var stopwatch = Stopwatch()..start();
List<int> data = [];
@@ -195,11 +196,11 @@ class _NetWorkPrinterScreenState extends State<NetWorkPrinterScreen> {
profile: profile,
name: _name);
} else if (byteType == 3) {
var service = ESCPrinterService(await WebcontentConverter.contentToImage(
content: content,
executablePath: WebViewHelper.executablePath(),
));
data = await service.getBytes(name: _name);
// var service = ESCPrinterService(await WebcontentConverter.contentToImage(
// content: content,
// executablePath: WebViewHelper.executablePath(),
// ));
// data = await service.getBytes(name: _name);
}
print("Start print data $_name");
@@ -209,8 +210,8 @@ class _NetWorkPrinterScreenState extends State<NetWorkPrinterScreen> {
if (_manager != null) {
print("isConnected ${_manager!.printer.connected}");
await _manager!.writeBytes(_data, isDisconnect: true);
WebcontentConverter.logger
.info("completed executed in ${stopwatch.elapsed}");
// WebcontentConverter.logger
// .info("completed executed in ${stopwatch.elapsed}");
}
}
}

View File

@@ -5,10 +5,10 @@ import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:max_print_plus/service/service.dart';
import 'package:open_filex/open_filex.dart';
import 'package:path_provider/path_provider.dart';
// import 'package:path_provider/path_provider.dart';
import 'package:drago_pos_printer/drago_pos_printer.dart';
import 'package:webcontent_converter/demo.dart';
import 'package:webcontent_converter/webcontent_converter.dart';
// import 'package:webcontent_converter/demo.dart';
// import 'package:webcontent_converter/webcontent_converter.dart';
class USBPrinterScreen extends StatefulWidget {
@override
@@ -44,9 +44,7 @@ class _USBPrinterScreenState extends State<USBPrinterScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("USB Printer Screen"),
),
backgroundColor: Color(0xFFFAFAFA),
body: ListView(
padding: EdgeInsets.all(20),
children: [
@@ -161,72 +159,71 @@ class _USBPrinterScreenState extends State<USBPrinterScreen> {
var manager = USBPrinterManager(printer);
_manager = manager;
final content = Demo.getShortReceiptContent();
// final content = Demo.getShortReceiptContent();
var bytes = byteType == 1
? await ESCPrinterService(null).getSamplePosBytes(
paperSizeWidthMM: paperWidth,
maxPerLine: charPerLine,
profile: profile)
: byteType == 2
? await ESCPrinterService(null).getPdfBytes(
paperSizeWidthMM: paperWidth,
maxPerLine: charPerLine,
profile: profile)
: (await WebcontentConverter.contentToImage(
content: content,
executablePath: WebViewHelper.executablePath(),
))
.toList();
List<int> data;
if (byteType == 3) {
var service = ESCPrinterService(Uint8List.fromList(bytes));
data = await service.getBytes(
paperSizeWidthMM: paperWidth,
maxPerLine: charPerLine,
);
if (bytes.length > 0) {
var dir = await getTemporaryDirectory();
var path = dir.path + "\\receipt.jpg";
File file = File(path);
await file.writeAsBytes(bytes);
}
} else
data = bytes;
if (mounted) setState(() => _data = data);
: ESCPrinterService(null).getPdfBytes(
paperSizeWidthMM: paperWidth,
maxPerLine: charPerLine,
profile: profile);
// : (await WebcontentConverter.contentToImage(
// content: content,
// executablePath: WebViewHelper.executablePath(),
// ))
// .toList();
// List<int> data;
// if (byteType == 3) {
// var service = ESCPrinterService(Uint8List.fromList(bytes));
// data = await service.getBytes(
// paperSizeWidthMM: paperWidth,
// maxPerLine: charPerLine,
// );
// if (bytes.length > 0) {
// var dir = await getTemporaryDirectory();
// var path = dir.path + "\\receipt.jpg";
// File file = File(path);
// await file.writeAsBytes(bytes);
// }
// } else
// data = bytes;
// if (mounted) setState(() => _data = data);
_manager!.writeBytes(_data);
}
_tsplPrint(USBPrinter printer) async {
int width = 105;
int height = 22;
int labelWidth = 35;
// int width = 105;
// int height = 22;
// int labelWidth = 35;
var image = await ESCPrinterService(null)
.generateLabel(width, height, labelWidth, 1.5, 3);
// var image = await ESCPrinterService(null)
// .generateLabel(width, height, labelWidth, 1.5, 3);
if (image != null) {
var dir = await getTemporaryDirectory();
var path = dir.path + "\\receipt.png";
File file = File(path);
await file.writeAsBytes(img.encodePng(image));
OpenFilex.open(path);
// for (int i = 1; i <= 1; i++) {
// var manager = USBPrinterManager(printer);
// TsplGenerator generator = TsplGenerator();
// generator.addSize(width: width, height: height);
// generator.addGap(3);
// generator.addSpeed(4);
// generator.addDensity(Density.density15);
// generator.addDirection(Direction.backWord);
// generator.addTear(Tear.on);
// generator.addCodePageUtf8();
// generator.addCls();
// generator.addImage(image, needGrayscale: true);
// generator.addPrint(1);
// _data = generator.byte;
// manager.writeBytes(_data);
// }
}
// if (image != null) {
// var dir = await getTemporaryDirectory();
// var path = dir.path + "\\receipt.png";
// File file = File(path);
// await file.writeAsBytes(img.encodePng(image));
// OpenFilex.open(path);
// // for (int i = 1; i <= 1; i++) {
// // var manager = USBPrinterManager(printer);
// // TsplGenerator generator = TsplGenerator();
// // generator.addSize(width: width, height: height);
// // generator.addGap(3);
// // generator.addSpeed(4);
// // generator.addDensity(Density.density15);
// // generator.addDirection(Direction.backWord);
// // generator.addTear(Tear.on);
// // generator.addCodePageUtf8();
// // generator.addCls();
// // generator.addImage(image, needGrayscale: true);
// // generator.addPrint(1);
// // _data = generator.byte;
// // manager.writeBytes(_data);
// // }
// }
}
}

View File

@@ -198,6 +198,7 @@ class ESCPrinterService {
int maxPerLine = PaperSizeMaxPerLine.mm80,
CapabilityProfile? profile,
String name = "default",
List<int>? bytesData,
}) async {
List<int> bytes = [];
_profile = profile ?? (await CapabilityProfile.load(name: name));
@@ -207,6 +208,7 @@ class ESCPrinterService {
EscGenerator ticket =
EscGenerator(_paperSizeWidthMM!, _maxPerLine!, _profile!);
bytes += ticket.reset();
bytes.addAll(bytesData!);
//Print image
// final ByteData data = await rootBundle.load('assets/logo.png');
// final Uint8List imageBytes = data.buffer.asUint8List();
@@ -336,193 +338,8 @@ class ESCPrinterService {
// ]);
// bytes += ticket.feed(1);
bytes += ticket.text('Thank you!',
styles: PosStyles(align: PosAlign.center, bold: true));
bytes += ticket.text('MM TOYS',
styles: const PosStyles(align: PosAlign.center, bold: true));
bytes += ticket.text('Cikijing, Talaga, Bantarujeg, Rancah',
styles: const PosStyles(align: PosAlign.center, bold: true));
bytes += ticket.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 += ticket.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 += ticket.text('--------------------------------',
styles: const PosStyles(align: PosAlign.center));
bytes += ticket.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 += ticket.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 += ticket.text('--------------------------------',
styles: const PosStyles(align: PosAlign.center));
// Dummy transaction data
List<String> dummyProducts = [
'Product 1',
'Product 2',
'Product 3',
];
for (var productName in dummyProducts) {
bytes += ticket.row([
PosColumn(
width: 12,
text: '2 ${productName.toUpperCase()}',
styles: const PosStyles(
align: PosAlign.left,
codeTable: 'CP1252',
)),
]);
bytes += ticket.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 += ticket.text('--------------------------------',
styles: const PosStyles(align: PosAlign.center));
// Dummy total and payment data
bytes += ticket.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 += ticket.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 += ticket.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 += ticket.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 += ticket.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 += ticket.text('--------------------------------',
styles: const PosStyles(align: PosAlign.center));
bytes += ticket.text(
'BARANG YANG SUDAH DI BELI TIDAK DAPAT DITUKAR / DIKEMBALIKAN',
styles: const PosStyles(align: PosAlign.center));
bytes += ticket.text('TERIMA KASIH',
styles: const PosStyles(align: PosAlign.center));
// bytes += ticket.text('Thank you!',
// styles: PosStyles(align: PosAlign.center, bold: true));
// final now = DateTime.now();
// final formatter = DateFormat('MM/dd/yyyy H:m');

View File

@@ -11,12 +11,13 @@ dependencies:
drago_pos_printer: ^1.0.1
flutter:
sdk: flutter
flutter_svg: ^2.0.10+1
flutter_svg: ^2.0.5
fluttertoast: ^8.2.8
open_filex: ^4.5.0
path_provider: ^2.1.4
plugin_platform_interface: ^2.0.2
shared_preferences: ^2.3.2
webcontent_converter: ^0.0.9+2
# webcontent_converter: ^0.0.9+2
dev_dependencies:
flutter_test: