first commit
This commit is contained in:
448
lib/max_print copy.dart
Normal file
448
lib/max_print copy.dart
Normal file
@@ -0,0 +1,448 @@
|
||||
// library max_print_dialog;
|
||||
|
||||
// import 'dart:async';
|
||||
// import 'dart:developer';
|
||||
// import 'dart:io';
|
||||
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:thermal_printer/esc_pos_utils_platform/esc_pos_utils_platform.dart';
|
||||
// import 'package:thermal_printer/thermal_printer.dart';
|
||||
// import 'my_button.dart';
|
||||
// import 'printer_devices.dart';
|
||||
|
||||
// class MaxPrintPage extends StatefulWidget {
|
||||
// Function()? onSuccess;
|
||||
// PreferredSizeWidget? appBar;
|
||||
// String? title, description;
|
||||
// Color? btnOkTextColor,
|
||||
// btnOkBorderColor,
|
||||
// btnOkColor,
|
||||
// btnCancelTextColor,
|
||||
// btnCancelBorderColor,
|
||||
// btnCancelColor;
|
||||
// double? btnRadius, btnHeight, btnWidth;
|
||||
// List<int> bytes;
|
||||
// Generator generator;
|
||||
// Function()? onCancelTap;
|
||||
|
||||
// MaxPrintPage(
|
||||
// {Key? key,
|
||||
// required this.appBar,
|
||||
// required this.bytes,
|
||||
// required this.generator,
|
||||
// this.onSuccess,
|
||||
// this.description,
|
||||
// this.title,
|
||||
// this.btnOkBorderColor,
|
||||
// this.btnOkColor,
|
||||
// this.btnRadius,
|
||||
// this.btnOkTextColor,
|
||||
// this.btnCancelBorderColor,
|
||||
// this.btnCancelColor,
|
||||
// this.btnCancelTextColor,
|
||||
// this.btnHeight,
|
||||
// this.btnWidth,
|
||||
// this.onCancelTap})
|
||||
// : super(key: key);
|
||||
|
||||
// @override
|
||||
// _MaxPrintPageState createState() => _MaxPrintPageState();
|
||||
// }
|
||||
|
||||
// class _MaxPrintPageState extends State<MaxPrintPage> {
|
||||
// bool isLoadingButton = false;
|
||||
|
||||
// // Thermal
|
||||
// var defaultPrinterType = PrinterType.bluetooth;
|
||||
// var _isBle = false;
|
||||
// var _reconnect = false;
|
||||
// var _isConnected = false;
|
||||
// var printerManager = PrinterManager.instance;
|
||||
// var devices = <PrinterDevices>[];
|
||||
// StreamSubscription<PrinterDevice>? _subscription;
|
||||
// StreamSubscription<BTStatus>? _subscriptionBtStatus;
|
||||
// StreamSubscription<USBStatus>? _subscriptionUsbStatus;
|
||||
// StreamSubscription<TCPStatus>? _subscriptionTCPStatus;
|
||||
// BTStatus _currentStatus = BTStatus.none;
|
||||
// // ignore: unused_field
|
||||
// TCPStatus _currentTCPStatus = TCPStatus.none;
|
||||
// // _currentUsbStatus is only supports on Android
|
||||
// // ignore: unused_field
|
||||
// USBStatus _currentUsbStatus = USBStatus.none;
|
||||
// List<int>? pendingTask;
|
||||
// final String _ipAddress = '';
|
||||
// String _port = '9100';
|
||||
// final _ipController = TextEditingController();
|
||||
// final _portController = TextEditingController();
|
||||
// PrinterDevices? selectedPrinter;
|
||||
|
||||
// @override
|
||||
// void initState() {
|
||||
// _initialize();
|
||||
// super.initState();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void dispose() {
|
||||
// _subscription?.cancel();
|
||||
// _subscriptionBtStatus?.cancel();
|
||||
// _subscriptionUsbStatus?.cancel();
|
||||
// _subscriptionTCPStatus?.cancel();
|
||||
// _portController.dispose();
|
||||
// _ipController.dispose();
|
||||
// super.dispose();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// backgroundColor: const Color(0xFFFAFAFA),
|
||||
// bottomNavigationBar: Padding(
|
||||
// padding: const EdgeInsets.all(16),
|
||||
// child: Row(
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
// children: [
|
||||
// Flexible(
|
||||
// child: MyButton(
|
||||
// width: double.infinity,
|
||||
// text: 'Tutup',
|
||||
// textColor: widget.btnCancelTextColor ?? Colors.black,
|
||||
// borderColor: widget.btnCancelBorderColor ?? Colors.amber,
|
||||
// color: widget.btnCancelColor ?? Colors.white,
|
||||
// press: widget.onCancelTap ??
|
||||
// () {
|
||||
// Navigator.pop(context);
|
||||
// })),
|
||||
// const SizedBox(
|
||||
// width: 16.0,
|
||||
// ),
|
||||
// Flexible(
|
||||
// child: MyButton(
|
||||
// width: double.infinity,
|
||||
// textColor: widget.btnOkTextColor,
|
||||
// borderColor: widget.btnOkBorderColor,
|
||||
// color: widget.btnOkColor,
|
||||
// text: 'Cetak',
|
||||
// press: () {
|
||||
// _printReceiveTest();
|
||||
// }))
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// appBar: widget.appBar,
|
||||
// body: _buildView(context));
|
||||
// }
|
||||
|
||||
// _buildView(BuildContext context) {
|
||||
// return Padding(
|
||||
// padding: const EdgeInsets.all(20.0),
|
||||
// child: ListView(
|
||||
// shrinkWrap: true,
|
||||
// children: [
|
||||
// const SizedBox(
|
||||
// height: 16.0,
|
||||
// ),
|
||||
// const Text(
|
||||
// 'Daftar perangkat :',
|
||||
// style: TextStyle(color: Color(0xFF0E0F0F), fontSize: 16.0),
|
||||
// ),
|
||||
// const SizedBox(
|
||||
// height: 10.0,
|
||||
// ),
|
||||
// // Row(
|
||||
// // children: [
|
||||
// // _chipOption(label: 'BT', val: PrinterType.bluetooth),
|
||||
// // _chipOption(label: 'IP', val: PrinterType.network),
|
||||
// // ],
|
||||
// // ),
|
||||
// Container(
|
||||
// decoration: BoxDecoration(
|
||||
// borderRadius: BorderRadius.circular(16.0), color: Colors.white),
|
||||
// child: Material(
|
||||
// color: Colors.transparent,
|
||||
// child: Column(
|
||||
// children: devices
|
||||
// .map(
|
||||
// (device) => ListTile(
|
||||
// title: Row(
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
// children: [
|
||||
// Text(
|
||||
// '${device.deviceName}',
|
||||
// maxLines: 1,
|
||||
// style: const TextStyle(
|
||||
// fontWeight: FontWeight.w600,
|
||||
// fontSize: 16.0),
|
||||
// ),
|
||||
// const SizedBox(
|
||||
// width: 6.0,
|
||||
// ),
|
||||
// selectedPrinter != null &&
|
||||
// ((device.typePrinter ==
|
||||
// PrinterType.usb &&
|
||||
// Platform.isWindows
|
||||
// ? device.deviceName ==
|
||||
// selectedPrinter!.deviceName
|
||||
// : device.vendorId != null &&
|
||||
// selectedPrinter!.vendorId ==
|
||||
// device.vendorId) ||
|
||||
// (device.address != null &&
|
||||
// selectedPrinter!.address ==
|
||||
// device.address))
|
||||
// ? const Icon(
|
||||
// Icons.check_circle,
|
||||
// color: Colors.green,
|
||||
// size: 16.0,
|
||||
// )
|
||||
// : const SizedBox()
|
||||
// ],
|
||||
// ),
|
||||
// subtitle: Platform.isAndroid &&
|
||||
// defaultPrinterType == PrinterType.usb
|
||||
// ? null
|
||||
// : Visibility(
|
||||
// visible: !Platform.isWindows,
|
||||
// child: Text("${device.address}")),
|
||||
// onTap: () async {
|
||||
// // do something
|
||||
// selectDevice(device);
|
||||
// _connectDevice();
|
||||
// await device.saveToPrefs();
|
||||
// },
|
||||
// trailing: Material(
|
||||
// color: Colors.transparent,
|
||||
// child: IconButton(
|
||||
// onPressed: selectedPrinter == null ||
|
||||
// device.deviceName !=
|
||||
// selectedPrinter?.deviceName
|
||||
// ? null
|
||||
// : () async {
|
||||
// _connectDevice();
|
||||
// await selectedPrinter!.saveToPrefs();
|
||||
// },
|
||||
// icon: Image.asset(
|
||||
// device.deviceName ==
|
||||
// selectedPrinter?.deviceName
|
||||
// ? 'assets/ic_connect_on.png'
|
||||
// : 'assets/ic_connect_off.png',
|
||||
// package: 'max_print_dialog',
|
||||
// )),
|
||||
// )),
|
||||
// )
|
||||
// .toList()),
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(
|
||||
// height: 16.0,
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
|
||||
// void _scan() {
|
||||
// devices.clear();
|
||||
// _subscription = printerManager
|
||||
// .discovery(type: defaultPrinterType, isBle: _isBle)
|
||||
// .listen((device) {
|
||||
// devices.add(PrinterDevices(
|
||||
// deviceName: device.name,
|
||||
// address: device.address,
|
||||
// isBle: _isBle,
|
||||
// vendorId: device.vendorId,
|
||||
// productId: device.productId,
|
||||
// typePrinter: defaultPrinterType,
|
||||
// ));
|
||||
// setState(() {});
|
||||
// });
|
||||
// }
|
||||
|
||||
// _connectDevice() async {
|
||||
// _isConnected = false;
|
||||
// if (selectedPrinter == null) return;
|
||||
// switch (selectedPrinter!.typePrinter) {
|
||||
// case PrinterType.usb:
|
||||
// await printerManager.connect(
|
||||
// type: selectedPrinter!.typePrinter,
|
||||
// model: UsbPrinterInput(
|
||||
// name: selectedPrinter!.deviceName,
|
||||
// productId: selectedPrinter!.productId,
|
||||
// vendorId: selectedPrinter!.vendorId));
|
||||
// _isConnected = true;
|
||||
// break;
|
||||
// case PrinterType.bluetooth:
|
||||
// await printerManager.connect(
|
||||
// type: selectedPrinter!.typePrinter,
|
||||
// model: BluetoothPrinterInput(
|
||||
// name: selectedPrinter!.deviceName,
|
||||
// address: selectedPrinter!.address!,
|
||||
// isBle: selectedPrinter!.isBle ?? false,
|
||||
// autoConnect: _reconnect));
|
||||
// break;
|
||||
// case PrinterType.network:
|
||||
// await printerManager.connect(
|
||||
// type: selectedPrinter!.typePrinter,
|
||||
// model: TcpPrinterInput(ipAddress: selectedPrinter!.address!));
|
||||
// _isConnected = true;
|
||||
// break;
|
||||
// default:
|
||||
// }
|
||||
|
||||
// setState(() {});
|
||||
// }
|
||||
|
||||
// void selectDevice(PrinterDevices device) async {
|
||||
// if (selectedPrinter != null) {
|
||||
// if ((device.address != selectedPrinter!.address) ||
|
||||
// (device.typePrinter == PrinterType.usb &&
|
||||
// selectedPrinter!.vendorId != device.vendorId)) {
|
||||
// await PrinterManager.instance
|
||||
// .disconnect(type: selectedPrinter!.typePrinter);
|
||||
// }
|
||||
// }
|
||||
|
||||
// selectedPrinter = device;
|
||||
// setState(() {});
|
||||
// }
|
||||
|
||||
// _printReceiveTest() {
|
||||
// _printEscPos(widget.bytes, widget.generator);
|
||||
|
||||
// widget.onSuccess!();
|
||||
// }
|
||||
|
||||
// /// print ticket
|
||||
// void _printEscPos(List<int> bytes, Generator generator) async {
|
||||
// var connectedTCP = false;
|
||||
// if (selectedPrinter == null) return;
|
||||
// var bluetoothPrinter = selectedPrinter!;
|
||||
// switch (bluetoothPrinter.typePrinter) {
|
||||
// case PrinterType.usb:
|
||||
// bytes += generator.feed(2);
|
||||
// bytes += generator.cut();
|
||||
// await printerManager.connect(
|
||||
// type: bluetoothPrinter.typePrinter,
|
||||
// model: UsbPrinterInput(
|
||||
// name: bluetoothPrinter.deviceName,
|
||||
// productId: bluetoothPrinter.productId,
|
||||
// vendorId: bluetoothPrinter.vendorId));
|
||||
// pendingTask = null;
|
||||
// break;
|
||||
// case PrinterType.bluetooth:
|
||||
// bytes += generator.cut();
|
||||
// await printerManager.connect(
|
||||
// type: bluetoothPrinter.typePrinter,
|
||||
// model: BluetoothPrinterInput(
|
||||
// name: bluetoothPrinter.deviceName,
|
||||
// address: bluetoothPrinter.address!,
|
||||
// isBle: bluetoothPrinter.isBle ?? false,
|
||||
// autoConnect: _reconnect));
|
||||
// pendingTask = null;
|
||||
// if (Platform.isAndroid) pendingTask = bytes;
|
||||
// break;
|
||||
// case PrinterType.network:
|
||||
// bytes += generator.feed(2);
|
||||
// bytes += generator.cut();
|
||||
// connectedTCP = await printerManager.connect(
|
||||
// type: bluetoothPrinter.typePrinter,
|
||||
// model: TcpPrinterInput(ipAddress: bluetoothPrinter.address!));
|
||||
// if (!connectedTCP) print(' --- please review your connection ---');
|
||||
// break;
|
||||
// default:
|
||||
// }
|
||||
// if (bluetoothPrinter.typePrinter == PrinterType.bluetooth &&
|
||||
// Platform.isAndroid) {
|
||||
// if (_currentStatus == BTStatus.connected) {
|
||||
// printerManager.send(type: bluetoothPrinter.typePrinter, bytes: bytes);
|
||||
// pendingTask = null;
|
||||
// }
|
||||
// } else {
|
||||
// printerManager.send(type: bluetoothPrinter.typePrinter, bytes: bytes);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Future<void> _initialize() async {
|
||||
// PrinterDevices? printer = await PrinterDevices.getFromPrefs();
|
||||
|
||||
// _scan();
|
||||
// if (printer != null) {
|
||||
// selectDevice(printer);
|
||||
// }
|
||||
|
||||
// // subscription to listen change status of bluetooth connection
|
||||
// _subscriptionBtStatus =
|
||||
// PrinterManager.instance.stateBluetooth.listen((status) {
|
||||
// log(' ----------------- status bt $status ------------------ ');
|
||||
// _currentStatus = status;
|
||||
// if (status == BTStatus.connected) {
|
||||
// setState(() {
|
||||
// _isConnected = true;
|
||||
// });
|
||||
// }
|
||||
// if (status == BTStatus.none) {
|
||||
// setState(() {
|
||||
// _isConnected = false;
|
||||
// });
|
||||
// }
|
||||
// if (status == BTStatus.connected && pendingTask != null) {
|
||||
// if (Platform.isAndroid) {
|
||||
// Future.delayed(const Duration(milliseconds: 1000), () {
|
||||
// PrinterManager.instance
|
||||
// .send(type: PrinterType.bluetooth, bytes: pendingTask!);
|
||||
// pendingTask = null;
|
||||
// });
|
||||
// } else if (Platform.isIOS) {
|
||||
// PrinterManager.instance
|
||||
// .send(type: PrinterType.bluetooth, bytes: pendingTask!);
|
||||
// pendingTask = null;
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// // PrinterManager.instance.stateUSB is only supports on Android
|
||||
// _subscriptionUsbStatus = PrinterManager.instance.stateUSB.listen((status) {
|
||||
// log(' ----------------- status usb $status ------------------ ');
|
||||
// _currentUsbStatus = status;
|
||||
// if (Platform.isAndroid) {
|
||||
// if (status == USBStatus.connected && pendingTask != null) {
|
||||
// Future.delayed(const Duration(milliseconds: 1000), () {
|
||||
// PrinterManager.instance
|
||||
// .send(type: PrinterType.usb, bytes: pendingTask!);
|
||||
// pendingTask = null;
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
// // PrinterManager.instance.stateUSB is only supports on Android
|
||||
// _subscriptionTCPStatus = PrinterManager.instance.stateTCP.listen((status) {
|
||||
// log(' ----------------- status tcp $status ------------------ ');
|
||||
// _currentTCPStatus = status;
|
||||
// });
|
||||
// }
|
||||
|
||||
// _chipOption({required String label, required PrinterType val}) {
|
||||
// return Row(
|
||||
// children: [
|
||||
// Radio(
|
||||
// value: val,
|
||||
// groupValue: defaultPrinterType,
|
||||
// onChanged: (v) {
|
||||
// setState(() {
|
||||
// defaultPrinterType = v!;
|
||||
// selectedPrinter = null;
|
||||
// _isBle = false;
|
||||
// _isConnected = false;
|
||||
// _scan();
|
||||
// });
|
||||
// }),
|
||||
// const SizedBox(
|
||||
// width: 10.0,
|
||||
// ),
|
||||
// Text(
|
||||
// label,
|
||||
// style: const TextStyle(fontSize: 16.0),
|
||||
// )
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
// }
|
0
lib/max_print_plus.dart
Normal file
0
lib/max_print_plus.dart
Normal file
17
lib/max_print_plus_method_channel.dart
Normal file
17
lib/max_print_plus_method_channel.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'max_print_plus_platform_interface.dart';
|
||||
|
||||
/// An implementation of [MaxPrintPlusPlatform] that uses method channels.
|
||||
class MethodChannelMaxPrintPlus extends MaxPrintPlusPlatform {
|
||||
/// The method channel used to interact with the native platform.
|
||||
@visibleForTesting
|
||||
final methodChannel = const MethodChannel('max_print_plus');
|
||||
|
||||
@override
|
||||
Future<String?> getPlatformVersion() async {
|
||||
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
|
||||
return version;
|
||||
}
|
||||
}
|
29
lib/max_print_plus_platform_interface.dart
Normal file
29
lib/max_print_plus_platform_interface.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
import 'max_print_plus_method_channel.dart';
|
||||
|
||||
abstract class MaxPrintPlusPlatform extends PlatformInterface {
|
||||
/// Constructs a MaxPrintPlusPlatform.
|
||||
MaxPrintPlusPlatform() : super(token: _token);
|
||||
|
||||
static final Object _token = Object();
|
||||
|
||||
static MaxPrintPlusPlatform _instance = MethodChannelMaxPrintPlus();
|
||||
|
||||
/// The default instance of [MaxPrintPlusPlatform] to use.
|
||||
///
|
||||
/// Defaults to [MethodChannelMaxPrintPlus].
|
||||
static MaxPrintPlusPlatform get instance => _instance;
|
||||
|
||||
/// Platform-specific implementations should set this with their own
|
||||
/// platform-specific class that extends [MaxPrintPlusPlatform] when
|
||||
/// they register themselves.
|
||||
static set instance(MaxPrintPlusPlatform instance) {
|
||||
PlatformInterface.verifyToken(instance, _token);
|
||||
_instance = instance;
|
||||
}
|
||||
|
||||
Future<String?> getPlatformVersion() {
|
||||
throw UnimplementedError('platformVersion() has not been implemented.');
|
||||
}
|
||||
}
|
73
lib/my_button.dart
Normal file
73
lib/my_button.dart
Normal file
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MyButton extends StatelessWidget {
|
||||
final String text;
|
||||
final Function()? press;
|
||||
final Color? color;
|
||||
final Color? textColor;
|
||||
final Color? borderColor;
|
||||
final double? width;
|
||||
final double? heigth;
|
||||
final double? borderRadius;
|
||||
final double? textSize;
|
||||
final EdgeInsetsGeometry? padding;
|
||||
|
||||
const MyButton(
|
||||
{Key? key,
|
||||
required this.text,
|
||||
required this.press,
|
||||
this.color,
|
||||
this.padding,
|
||||
this.textColor,
|
||||
this.width,
|
||||
this.heigth,
|
||||
this.borderRadius,
|
||||
this.borderColor,
|
||||
this.textSize})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: heigth,
|
||||
width: width,
|
||||
child: ElevatedButton(
|
||||
onPressed: press,
|
||||
style: ButtonStyle(
|
||||
elevation: MaterialStateProperty.all(0),
|
||||
padding: MaterialStateProperty.all(
|
||||
padding ?? const EdgeInsets.all(16.0)),
|
||||
backgroundColor: MaterialStateProperty.resolveWith<Color>(
|
||||
(Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return Color(0xFFDCDEE0);
|
||||
} else if (states.contains(MaterialState.disabled)) {
|
||||
return Color(0xFFF2F2F5);
|
||||
} else if (states.contains(MaterialState.focused)) {
|
||||
return Color(0xFFFFC700);
|
||||
}
|
||||
return color ??
|
||||
Color(0xFFFFC700); // Use the component's default.
|
||||
},
|
||||
),
|
||||
textStyle: MaterialStateProperty.all<TextStyle>(
|
||||
TextStyle(color: textColor ?? Color(0xFF242632))),
|
||||
shape: MaterialStateProperty.resolveWith<RoundedRectangleBorder>(
|
||||
(states) {
|
||||
return RoundedRectangleBorder(
|
||||
side: !(states.contains(MaterialState.pressed))
|
||||
? BorderSide(color: borderColor ?? Colors.transparent)
|
||||
: const BorderSide(color: Colors.transparent),
|
||||
borderRadius:
|
||||
BorderRadius.circular(borderRadius ?? 1000.0));
|
||||
})),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: textColor ?? Colors.white,
|
||||
fontSize: textSize,
|
||||
fontWeight: FontWeight.w600),
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
195
lib/print/bluetooth_printer_screen.dart
Normal file
195
lib/print/bluetooth_printer_screen.dart
Normal file
@@ -0,0 +1,195 @@
|
||||
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 '../service/service.dart';
|
||||
|
||||
class BluetoothPrinterScreen extends StatefulWidget {
|
||||
@override
|
||||
_BluetoothPrinterScreenState createState() => _BluetoothPrinterScreenState();
|
||||
}
|
||||
|
||||
class _BluetoothPrinterScreenState extends State<BluetoothPrinterScreen> {
|
||||
bool _isLoading = false;
|
||||
List<BluetoothPrinter> _printers = [];
|
||||
BluetoothPrinterManager? _manager;
|
||||
|
||||
int paperWidth = 0;
|
||||
int charPerLine = 0;
|
||||
|
||||
List<String> paperTypes = [];
|
||||
bool showCustom = false;
|
||||
@override
|
||||
void initState() {
|
||||
_scan();
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
|
||||
paperTypes.add('58mm');
|
||||
paperTypes.add('80mmOld');
|
||||
paperTypes.add('80mm');
|
||||
paperTypes.add('Custom');
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Bluetooth Printer Screen"),
|
||||
),
|
||||
body: ListView(
|
||||
padding: EdgeInsets.all(20),
|
||||
children: [
|
||||
DropdownButtonHideUnderline(
|
||||
child: DropdownButtonFormField(
|
||||
decoration: InputDecoration(labelText: 'Paper Size'),
|
||||
items: paperTypes.map((item) {
|
||||
return DropdownMenuItem(
|
||||
value: item,
|
||||
child: Text(item),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? selected) async {
|
||||
showCustom = false;
|
||||
if (selected != null) {
|
||||
if (selected == "58mm") {
|
||||
paperWidth = PaperSizeWidth.mm58;
|
||||
charPerLine = PaperSizeMaxPerLine.mm58;
|
||||
} else if (selected == "80mmOld") {
|
||||
paperWidth = PaperSizeWidth.mm80_Old;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80_Old;
|
||||
} else if (selected == "80mm") {
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
} else if (selected == "Custom") {
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
showCustom = true;
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
if (showCustom)
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
initialValue: paperWidth.toString(),
|
||||
onChanged: (val) {
|
||||
if (val.isNotEmpty) {
|
||||
paperWidth = int.parse(val);
|
||||
} else
|
||||
paperWidth = 0;
|
||||
},
|
||||
)),
|
||||
SizedBox(width: 20),
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
initialValue: charPerLine.toString(),
|
||||
onChanged: (val) {
|
||||
if (val.isNotEmpty) {
|
||||
charPerLine = int.parse(val);
|
||||
} else
|
||||
charPerLine = 0;
|
||||
},
|
||||
))
|
||||
],
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
..._printers
|
||||
.map((printer) => ListTile(
|
||||
title: Text("${printer.name}"),
|
||||
subtitle: Text("${printer.address}"),
|
||||
leading: Icon(Icons.bluetooth),
|
||||
onTap: () => _connect(printer),
|
||||
trailing: printer.connected
|
||||
? Wrap(
|
||||
children: [
|
||||
IconButton(
|
||||
tooltip: 'ESC POS Command',
|
||||
onPressed: () => _startPrinter(1, printer),
|
||||
icon: Icon(Icons.print)),
|
||||
IconButton(
|
||||
tooltip: 'Html Print',
|
||||
onPressed: () => _startPrinter(3, printer),
|
||||
icon: Icon(Icons.image)),
|
||||
],
|
||||
)
|
||||
: null,
|
||||
selected: printer.connected,
|
||||
))
|
||||
.toList(),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: _isLoading ? Icon(Icons.stop) : Icon(Icons.play_arrow),
|
||||
onPressed: _isLoading ? null : _scan,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_scan() async {
|
||||
print("scan");
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_printers = [];
|
||||
});
|
||||
var printers = await BluetoothPrinterManager.discover();
|
||||
print(printers);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_printers = printers;
|
||||
});
|
||||
}
|
||||
|
||||
Future _connect(BluetoothPrinter printer) async {
|
||||
var manager = BluetoothPrinterManager(printer);
|
||||
// await manager.connect();
|
||||
print(" -==== connected =====- ");
|
||||
setState(() {
|
||||
_manager = manager;
|
||||
printer.connected = true;
|
||||
});
|
||||
}
|
||||
|
||||
_startPrinter(int byteType, BluetoothPrinter printer) async {
|
||||
var profile = await CapabilityProfile.load();
|
||||
await _connect(printer);
|
||||
|
||||
late List<int> data;
|
||||
if (byteType == 1) {
|
||||
data = await ESCPrinterService(null).getSamplePosBytes(
|
||||
paperSizeWidthMM: paperWidth,
|
||||
maxPerLine: charPerLine,
|
||||
profile: profile);
|
||||
} else if (byteType == 2) {
|
||||
data = await ESCPrinterService(null).getPdfBytes(
|
||||
paperSizeWidthMM: paperWidth,
|
||||
maxPerLine: charPerLine,
|
||||
profile: profile);
|
||||
} else if (byteType == 3) {
|
||||
final content = Demo.getShortReceiptContent();
|
||||
|
||||
Uint8List? htmlBytes = await WebcontentConverter.contentToImage(
|
||||
content: content,
|
||||
executablePath: WebViewHelper.executablePath(),
|
||||
);
|
||||
|
||||
var service = ESCPrinterService(htmlBytes);
|
||||
data = await service.getBytes(
|
||||
paperSizeWidthMM: paperWidth,
|
||||
maxPerLine: charPerLine,
|
||||
profile: profile);
|
||||
}
|
||||
|
||||
if (_manager != null) {
|
||||
if (!await _manager!.checkConnected()) await _manager!.connect();
|
||||
_manager!.writeBytes(data, isDisconnect: true);
|
||||
}
|
||||
}
|
||||
}
|
117
lib/print/max_print.dart
Normal file
117
lib/print/max_print.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
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';
|
||||
import 'package:max_print_plus/print/usb_printer_screen.dart';
|
||||
|
||||
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);
|
||||
|
||||
@override
|
||||
State<MaxPrint> createState() => _MaxPrintState();
|
||||
}
|
||||
|
||||
class _MaxPrintState extends State<MaxPrint> with TickerProviderStateMixin {
|
||||
String? uid;
|
||||
bool? isLogin;
|
||||
late final TabController _tabController;
|
||||
@override
|
||||
void initState() {
|
||||
_tabController = TabController(length: 3, vsync: this);
|
||||
_tabController.addListener(_handleTabSelection);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
int tabIndex = 0;
|
||||
|
||||
void _handleTabSelection() {
|
||||
setState(() {
|
||||
tabIndex = _tabController.index;
|
||||
print('Tab index: $tabIndex');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: DefaultTabController(
|
||||
length: 3,
|
||||
child: Scaffold(
|
||||
backgroundColor: Color(0xFFFAFAFA),
|
||||
appBar: AppBar(
|
||||
title: Text('Print'),
|
||||
bottom: CustomTabBar(
|
||||
tabController: _tabController,
|
||||
tabs: [
|
||||
tabTitle('Bluetooth'),
|
||||
tabTitle('WiFi'),
|
||||
tabTitle('USB'),
|
||||
// tabTitle('Ongoing'),
|
||||
// tabTitle('Completed'),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
BluetoothPrinterScreen(),
|
||||
NetWorkPrinterScreen(),
|
||||
USBPrinterScreen()
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Tab tabTitle(String title) {
|
||||
return Tab(
|
||||
icon: Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
// color: Pallete.primary,
|
||||
fontSize: 12.0,
|
||||
fontWeight: FontWeight.w600,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
letterSpacing: 0.1),
|
||||
maxLines: 1,
|
||||
),
|
||||
);
|
||||
}
|
216
lib/print/network_printer_screen.dart
Normal file
216
lib/print/network_printer_screen.dart
Normal file
@@ -0,0 +1,216 @@
|
||||
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 '../service/service.dart';
|
||||
|
||||
class NetWorkPrinterScreen extends StatefulWidget {
|
||||
@override
|
||||
_NetWorkPrinterScreenState createState() => _NetWorkPrinterScreenState();
|
||||
}
|
||||
|
||||
class _NetWorkPrinterScreenState extends State<NetWorkPrinterScreen> {
|
||||
bool _isLoading = false;
|
||||
List<NetWorkPrinter> _printers = [];
|
||||
NetworkPrinterManager? _manager;
|
||||
List<int> _data = [];
|
||||
String _name = "default";
|
||||
|
||||
int paperWidth = 0;
|
||||
int charPerLine = 0;
|
||||
|
||||
List<String> paperTypes = [];
|
||||
bool showCustom = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_scan();
|
||||
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
|
||||
paperTypes.add('58mm');
|
||||
paperTypes.add('80mmOld');
|
||||
paperTypes.add('80mm');
|
||||
paperTypes.add('Custom');
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Network Printer Screen ${printProfiles.length}"),
|
||||
actions: [
|
||||
PopupMenuButton(
|
||||
itemBuilder: (_) => printProfiles
|
||||
.map(
|
||||
(e) => PopupMenuItem(
|
||||
enabled: e["key"] != _name,
|
||||
child: Text("${e["key"]}"),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_name = e["key"];
|
||||
});
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
)
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
padding: EdgeInsets.all(20),
|
||||
children: [
|
||||
DropdownButtonHideUnderline(
|
||||
child: DropdownButtonFormField(
|
||||
decoration: InputDecoration(labelText: 'Paper Size'),
|
||||
items: paperTypes.map((item) {
|
||||
return DropdownMenuItem(
|
||||
value: item,
|
||||
child: Text(item),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? selected) async {
|
||||
showCustom = false;
|
||||
if (selected != null) {
|
||||
if (selected == "58mm") {
|
||||
paperWidth = PaperSizeWidth.mm58;
|
||||
charPerLine = PaperSizeMaxPerLine.mm58;
|
||||
} else if (selected == "80mmOld") {
|
||||
paperWidth = PaperSizeWidth.mm80_Old;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80_Old;
|
||||
} else if (selected == "80mm") {
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
} else if (selected == "Custom") {
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
showCustom = true;
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
if (showCustom)
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
initialValue: paperWidth.toString(),
|
||||
onChanged: (val) {
|
||||
if (val.isNotEmpty) {
|
||||
paperWidth = int.parse(val);
|
||||
} else
|
||||
paperWidth = 0;
|
||||
},
|
||||
)),
|
||||
SizedBox(width: 20),
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
initialValue: charPerLine.toString(),
|
||||
onChanged: (val) {
|
||||
if (val.isNotEmpty) {
|
||||
charPerLine = int.parse(val);
|
||||
} else
|
||||
charPerLine = 0;
|
||||
},
|
||||
))
|
||||
],
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
..._printers
|
||||
.map((printer) => ListTile(
|
||||
title: Text("${printer.name}"),
|
||||
subtitle: Text("${printer.address}"),
|
||||
leading: Icon(Icons.cable),
|
||||
onTap: () => _connect(printer),
|
||||
trailing: printer.connected
|
||||
? Wrap(
|
||||
children: [
|
||||
IconButton(
|
||||
tooltip: 'ESC POS Command',
|
||||
onPressed: () => _startPrinter(1, printer),
|
||||
icon: Icon(Icons.print)),
|
||||
IconButton(
|
||||
tooltip: 'Html Print',
|
||||
onPressed: () => _startPrinter(3, printer),
|
||||
icon: Icon(Icons.image)),
|
||||
],
|
||||
)
|
||||
: null,
|
||||
selected: printer.connected,
|
||||
))
|
||||
.toList(),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: _isLoading ? Icon(Icons.stop) : Icon(Icons.play_arrow),
|
||||
onPressed: _isLoading ? null : _scan,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_scan() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_printers = [];
|
||||
});
|
||||
var printers = await NetworkPrinterManager.discover();
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_printers = printers;
|
||||
});
|
||||
}
|
||||
|
||||
Future _connect(NetWorkPrinter printer) async {
|
||||
var manager = NetworkPrinterManager(printer);
|
||||
await manager.connect();
|
||||
setState(() {
|
||||
_manager = manager;
|
||||
printer.connected = true;
|
||||
});
|
||||
}
|
||||
|
||||
_startPrinter(int byteType, NetWorkPrinter printer) async {
|
||||
await _connect(printer);
|
||||
// if (_data.isEmpty) {
|
||||
final content = Demo.getShortReceiptContent();
|
||||
|
||||
var stopwatch = Stopwatch()..start();
|
||||
List<int> data = [];
|
||||
var profile = await CapabilityProfile.load();
|
||||
if (byteType == 1) {
|
||||
data = await ESCPrinterService(null).getSamplePosBytes(
|
||||
paperSizeWidthMM: paperWidth,
|
||||
maxPerLine: charPerLine,
|
||||
profile: profile,
|
||||
name: _name);
|
||||
} else if (byteType == 2) {
|
||||
data = await ESCPrinterService(null).getPdfBytes(
|
||||
paperSizeWidthMM: paperWidth,
|
||||
maxPerLine: charPerLine,
|
||||
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);
|
||||
}
|
||||
|
||||
print("Start print data $_name");
|
||||
|
||||
if (mounted) setState(() => _data = data);
|
||||
|
||||
if (_manager != null) {
|
||||
print("isConnected ${_manager!.printer.connected}");
|
||||
await _manager!.writeBytes(_data, isDisconnect: true);
|
||||
WebcontentConverter.logger
|
||||
.info("completed executed in ${stopwatch.elapsed}");
|
||||
}
|
||||
}
|
||||
}
|
46
lib/print/tab_bar.dart
Normal file
46
lib/print/tab_bar.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/theme.config.dart';
|
||||
|
||||
class CustomTabBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
const CustomTabBar({
|
||||
Key? key,
|
||||
required TabController tabController,
|
||||
required List<Widget> tabs,
|
||||
}) : _tabController = tabController,
|
||||
_tabs = tabs,
|
||||
super(key: key);
|
||||
|
||||
final TabController _tabController;
|
||||
final List<Widget> _tabs;
|
||||
|
||||
@override
|
||||
Size get preferredSize => const Size(double.infinity, 45);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return disableMaterial3(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
height: 40,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
isScrollable: false,
|
||||
indicator: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
color: Colors.white,
|
||||
),
|
||||
indicatorColor: Colors.white,
|
||||
labelColor: Colors.black,
|
||||
unselectedLabelColor: Colors.grey,
|
||||
tabs: _tabs,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
232
lib/print/usb_printer_screen.dart
Normal file
232
lib/print/usb_printer_screen.dart
Normal file
@@ -0,0 +1,232 @@
|
||||
import 'package:image/image.dart' as img;
|
||||
import 'dart:io';
|
||||
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:drago_pos_printer/drago_pos_printer.dart';
|
||||
import 'package:webcontent_converter/demo.dart';
|
||||
import 'package:webcontent_converter/webcontent_converter.dart';
|
||||
|
||||
class USBPrinterScreen extends StatefulWidget {
|
||||
@override
|
||||
_USBPrinterScreenState createState() => _USBPrinterScreenState();
|
||||
}
|
||||
|
||||
class _USBPrinterScreenState extends State<USBPrinterScreen> {
|
||||
bool _isLoading = false;
|
||||
List<USBPrinter> _printers = [];
|
||||
USBPrinterManager? _manager;
|
||||
List<int> _data = [];
|
||||
|
||||
int paperWidth = 0;
|
||||
int charPerLine = 0;
|
||||
|
||||
List<String> paperTypes = [];
|
||||
bool showCustom = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_scan();
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
|
||||
paperTypes.add('58mm');
|
||||
paperTypes.add('80mmOld');
|
||||
paperTypes.add('80mm');
|
||||
paperTypes.add('Custom');
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("USB Printer Screen"),
|
||||
),
|
||||
body: ListView(
|
||||
padding: EdgeInsets.all(20),
|
||||
children: [
|
||||
DropdownButtonHideUnderline(
|
||||
child: DropdownButtonFormField(
|
||||
decoration: InputDecoration(labelText: 'Paper Size'),
|
||||
items: paperTypes.map((item) {
|
||||
return DropdownMenuItem(
|
||||
value: item,
|
||||
child: Text(item),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? selected) async {
|
||||
showCustom = false;
|
||||
if (selected != null) {
|
||||
if (selected == "58mm") {
|
||||
paperWidth = PaperSizeWidth.mm58;
|
||||
charPerLine = PaperSizeMaxPerLine.mm58;
|
||||
} else if (selected == "80mmOld") {
|
||||
paperWidth = PaperSizeWidth.mm80_Old;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80_Old;
|
||||
} else if (selected == "80mm") {
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
} else if (selected == "Custom") {
|
||||
paperWidth = PaperSizeWidth.mm80;
|
||||
charPerLine = PaperSizeMaxPerLine.mm80;
|
||||
showCustom = true;
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
if (showCustom)
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
initialValue: paperWidth.toString(),
|
||||
onChanged: (val) {
|
||||
if (val.isNotEmpty) {
|
||||
paperWidth = int.parse(val);
|
||||
} else
|
||||
paperWidth = 0;
|
||||
},
|
||||
)),
|
||||
SizedBox(width: 20),
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
initialValue: charPerLine.toString(),
|
||||
onChanged: (val) {
|
||||
if (val.isNotEmpty) {
|
||||
charPerLine = int.parse(val);
|
||||
} else
|
||||
charPerLine = 0;
|
||||
},
|
||||
))
|
||||
],
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
..._printers
|
||||
.map((printer) => ListTile(
|
||||
title: Text("${printer.name}"),
|
||||
subtitle: Text("${printer.address}"),
|
||||
leading: Icon(Icons.usb),
|
||||
trailing: Wrap(
|
||||
children: [
|
||||
IconButton(
|
||||
tooltip: 'Tspl Command',
|
||||
onPressed: () => _tsplPrint(printer),
|
||||
icon: Icon(Icons.qr_code)),
|
||||
IconButton(
|
||||
tooltip: 'ESC POS Command',
|
||||
onPressed: () => _startPrinter(1, printer),
|
||||
icon: Icon(Icons.print)),
|
||||
IconButton(
|
||||
tooltip: 'Pdf',
|
||||
onPressed: () => _startPrinter(2, printer),
|
||||
icon: Icon(Icons.picture_as_pdf)),
|
||||
IconButton(
|
||||
tooltip: 'Html Print',
|
||||
onPressed: () => _startPrinter(3, printer),
|
||||
icon: Icon(Icons.image)),
|
||||
],
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: _isLoading ? Icon(Icons.stop) : Icon(Icons.play_arrow),
|
||||
onPressed: _isLoading ? null : _scan,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_scan() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_printers = [];
|
||||
});
|
||||
var printers = await USBPrinterManager.discover();
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_printers = printers;
|
||||
});
|
||||
}
|
||||
|
||||
_startPrinter(int byteType, USBPrinter printer) async {
|
||||
var profile = await CapabilityProfile.load();
|
||||
var manager = USBPrinterManager(printer);
|
||||
_manager = manager;
|
||||
|
||||
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);
|
||||
|
||||
_manager!.writeBytes(_data);
|
||||
}
|
||||
|
||||
_tsplPrint(USBPrinter printer) async {
|
||||
int width = 105;
|
||||
int height = 22;
|
||||
int labelWidth = 35;
|
||||
|
||||
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);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
561
lib/service/service.dart
Normal file
561
lib/service/service.dart
Normal file
@@ -0,0 +1,561 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:image/image.dart' as img;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdf/pdf.dart' as pf;
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:drago_pos_printer/drago_pos_printer.dart';
|
||||
import 'package:printing/printing.dart';
|
||||
// import 'package:qr_flutter/qr_flutter.dart';
|
||||
import 'dart:math' as math;
|
||||
|
||||
class ESCPrinterService {
|
||||
final Uint8List? receipt;
|
||||
List<int>? _bytes;
|
||||
|
||||
var dpi;
|
||||
List<int>? get bytes => _bytes;
|
||||
int? _paperSizeWidthMM;
|
||||
int? _maxPerLine;
|
||||
CapabilityProfile? _profile;
|
||||
|
||||
ESCPrinterService(this.receipt);
|
||||
|
||||
Future<List<int>> getBytes({
|
||||
int paperSizeWidthMM = PaperSizeWidth.mm80,
|
||||
int maxPerLine = PaperSizeMaxPerLine.mm80,
|
||||
CapabilityProfile? profile,
|
||||
String name = "default",
|
||||
}) async {
|
||||
List<int> bytes = [];
|
||||
_profile = profile ?? (await CapabilityProfile.load(name: name));
|
||||
print(_profile!.name);
|
||||
_paperSizeWidthMM = paperSizeWidthMM;
|
||||
_maxPerLine = maxPerLine;
|
||||
assert(receipt != null);
|
||||
assert(_profile != null);
|
||||
EscGenerator generator =
|
||||
EscGenerator(_paperSizeWidthMM!, _maxPerLine!, _profile!);
|
||||
var decodeImage = img.decodeImage(receipt!);
|
||||
if (decodeImage == null) throw Exception('decoded image is null');
|
||||
final img.Image _resize =
|
||||
img.copyResize(decodeImage, width: _paperSizeWidthMM);
|
||||
|
||||
String dir = (await getTemporaryDirectory()).path;
|
||||
String fullPath = '$dir/abc.png';
|
||||
print("local file full path ${fullPath}");
|
||||
File file = File(fullPath);
|
||||
|
||||
await file.writeAsBytes(img.encodePng(decodeImage));
|
||||
|
||||
// OpenFile.open(fullPath);
|
||||
|
||||
bytes += generator.image(_resize);
|
||||
bytes += generator.feed(2);
|
||||
bytes += generator.cut();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
Future<img.Image?> generateLabel(int width, int height, int labelWidth,
|
||||
double horizontalGap, int column) async {
|
||||
final doc = pw.Document();
|
||||
doc.addPage(
|
||||
pw.Page(
|
||||
pageFormat: pf.PdfPageFormat(
|
||||
width * pf.PdfPageFormat.mm, height * pf.PdfPageFormat.mm),
|
||||
build: (pw.Context context) => pw.Row(children: [
|
||||
for (int i = 0; i < column; i++)
|
||||
pw.Expanded(
|
||||
child: pw.Center(
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
mainAxisAlignment: pw.MainAxisAlignment.center,
|
||||
children: [
|
||||
pw.SizedBox(height: 5),
|
||||
pw.Text('Bodi ananatham department',
|
||||
style: pw.TextStyle(fontSize: 6),
|
||||
overflow: pw.TextOverflow.clip),
|
||||
pw.SizedBox(height: 1),
|
||||
//barcode
|
||||
pw.BarcodeWidget(
|
||||
width: 90,
|
||||
height: 28,
|
||||
data: '324324',
|
||||
barcode: pw.Barcode.code39()),
|
||||
//qr code
|
||||
pw.Row(children: [
|
||||
pw.Container(
|
||||
width: 3,
|
||||
child: pw.Transform.rotateBox(
|
||||
angle: math.pi / 180,
|
||||
child: pw.Text(
|
||||
'13232',
|
||||
style: pw.TextStyle(fontSize: 5),
|
||||
),
|
||||
),
|
||||
),
|
||||
pw.SizedBox(width: 2),
|
||||
pw.BarcodeWidget(
|
||||
width: 26,
|
||||
height: 26,
|
||||
data: '324324',
|
||||
barcode: pw.Barcode.qrCode()),
|
||||
pw.SizedBox(width: 5),
|
||||
pw.Expanded(
|
||||
child: pw.Column(children: [
|
||||
pw.Row(children: [
|
||||
pw.Expanded(
|
||||
child: pw.Text('Rate',
|
||||
style: pw.TextStyle(fontSize: 6))),
|
||||
pw.Expanded(
|
||||
child: pw.Text('0.52',
|
||||
style: pw.TextStyle(fontSize: 6))),
|
||||
]),
|
||||
pw.Row(children: [
|
||||
pw.Expanded(
|
||||
child: pw.Text('MRP',
|
||||
style: pw.TextStyle(fontSize: 6))),
|
||||
pw.Expanded(
|
||||
child: pw.Text('0.52',
|
||||
style: pw.TextStyle(fontSize: 6))),
|
||||
]),
|
||||
pw.Row(children: [
|
||||
pw.Expanded(
|
||||
child: pw.Text('Mfd',
|
||||
style: pw.TextStyle(fontSize: 6))),
|
||||
pw.Expanded(
|
||||
child: pw.Text('02/20/23',
|
||||
style: pw.TextStyle(fontSize: 6))),
|
||||
]),
|
||||
pw.Row(children: [
|
||||
pw.Expanded(
|
||||
child: pw.Text('Expiry',
|
||||
style: pw.TextStyle(fontSize: 6))),
|
||||
pw.Expanded(
|
||||
child: pw.Text('02/20/23',
|
||||
style: pw.TextStyle(fontSize: 6))),
|
||||
]),
|
||||
])),
|
||||
pw.SizedBox(width: 3),
|
||||
]),
|
||||
pw.SizedBox(height: 1.5),
|
||||
pw.Text('200g Horlicks Choclate flavor [iyj fdgdfgdf dfgdfg]',
|
||||
style: pw.TextStyle(fontSize: 6)),
|
||||
])))
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
||||
await for (var page in Printing.raster(await doc.save(), dpi: 203)) {
|
||||
return page.asImage();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<Uint8List> _generatePdf() async {
|
||||
final doc = pw.Document();
|
||||
doc.addPage(
|
||||
pw.Page(
|
||||
pageFormat: pf.PdfPageFormat.roll57,
|
||||
build: (pw.Context context) => pw.SizedBox(
|
||||
height: 10 * pf.PdfPageFormat.mm,
|
||||
child: pw.Center(
|
||||
child: pw.Text('Hello World', style: pw.TextStyle(fontSize: 20)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return doc.save();
|
||||
}
|
||||
|
||||
Future<List<int>> getPdfBytes({
|
||||
int paperSizeWidthMM = PaperSizeMaxPerLine.mm80,
|
||||
int maxPerLine = PaperSizeMaxPerLine.mm80,
|
||||
CapabilityProfile? profile,
|
||||
String name = "default",
|
||||
}) async {
|
||||
List<int> bytes = [];
|
||||
_profile = profile ?? (await CapabilityProfile.load(name: name));
|
||||
print(_profile!.name);
|
||||
_paperSizeWidthMM = paperSizeWidthMM;
|
||||
_maxPerLine = maxPerLine;
|
||||
|
||||
EscGenerator generator =
|
||||
EscGenerator(_paperSizeWidthMM!, _maxPerLine!, _profile!);
|
||||
|
||||
await for (var page in Printing.raster(await _generatePdf(), dpi: 96)) {
|
||||
final image = page.asImage();
|
||||
bytes += generator.image(image);
|
||||
bytes += generator.reset();
|
||||
bytes += generator.cut();
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
Future<List<int>> getSamplePosBytes({
|
||||
int paperSizeWidthMM = PaperSizeMaxPerLine.mm80,
|
||||
int maxPerLine = PaperSizeMaxPerLine.mm80,
|
||||
CapabilityProfile? profile,
|
||||
String name = "default",
|
||||
}) async {
|
||||
List<int> bytes = [];
|
||||
_profile = profile ?? (await CapabilityProfile.load(name: name));
|
||||
print(_profile!.name);
|
||||
_paperSizeWidthMM = paperSizeWidthMM;
|
||||
_maxPerLine = maxPerLine;
|
||||
EscGenerator ticket =
|
||||
EscGenerator(_paperSizeWidthMM!, _maxPerLine!, _profile!);
|
||||
bytes += ticket.reset();
|
||||
//Print image
|
||||
// final ByteData data = await rootBundle.load('assets/logo.png');
|
||||
// final Uint8List imageBytes = data.buffer.asUint8List();
|
||||
// final img.Image? image = img.decodeImage(imageBytes);
|
||||
// if (image != null) {
|
||||
// img.Image thumbnail = img.copyResize(image, width: 400);
|
||||
// bytes += ticket.image(thumbnail);
|
||||
// bytes += ticket.reset();
|
||||
// }
|
||||
|
||||
// bytes += ticket.text(
|
||||
// 'Regular: aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ');
|
||||
// bytes += ticket.text('Special 1: ', styles: PosStyles(codeTable: 'CP1252'));
|
||||
// bytes += ticket.text('Special 2: blåbærgrød',
|
||||
// styles: PosStyles(codeTable: 'CP1252'));
|
||||
|
||||
// bytes += ticket.text('Bold text', styles: PosStyles(bold: true));
|
||||
// bytes += ticket.text('Reverse text', styles: PosStyles(reverse: true));
|
||||
// bytes += ticket.text('Underlined text',
|
||||
// styles: PosStyles(underline: true), linesAfter: 1);
|
||||
// bytes += ticket.text('Align left', styles: PosStyles(align: PosAlign.left));
|
||||
// bytes +=
|
||||
// ticket.text('Align center', styles: PosStyles(align: PosAlign.center));
|
||||
// bytes += ticket.text('Align right',
|
||||
// styles: PosStyles(align: PosAlign.right), linesAfter: 1);
|
||||
|
||||
// bytes += ticket.text('SKS DEPARTMENT STORE',
|
||||
// styles: PosStyles(
|
||||
// align: PosAlign.center,
|
||||
// height: PosTextSize.size1,
|
||||
// width: PosTextSize.size1,
|
||||
// ));
|
||||
|
||||
// bytes += ticket.text('889 Watson Lane',
|
||||
// styles: PosStyles(align: PosAlign.center));
|
||||
// bytes += ticket.text('New Braunfels, TX',
|
||||
// styles: PosStyles(align: PosAlign.center));
|
||||
// bytes += ticket.text('Tel: 830-221-1234',
|
||||
// styles: PosStyles(align: PosAlign.center));
|
||||
// bytes +=
|
||||
// ticket.text('Web: .com', styles: PosStyles(align: PosAlign.center));
|
||||
|
||||
// bytes += ticket.hr();
|
||||
// bytes += ticket.row([
|
||||
// PosColumn(text: 'Qty', width: 1),
|
||||
// PosColumn(text: 'Item', width: 5),
|
||||
// PosColumn(
|
||||
// text: 'Price', width: 3, styles: PosStyles(align: PosAlign.right)),
|
||||
// PosColumn(
|
||||
// text: 'Total ', width: 3, styles: PosStyles(align: PosAlign.right)),
|
||||
// ]);
|
||||
// bytes += ticket.hr();
|
||||
|
||||
// bytes += ticket.row([
|
||||
// PosColumn(text: '2', width: 1),
|
||||
// PosColumn(text: 'ONION RINGS ONION RINGS ONION', width: 5),
|
||||
// PosColumn(
|
||||
// text: '0.99', width: 3, styles: PosStyles(align: PosAlign.right)),
|
||||
// PosColumn(
|
||||
// text: '1.98', width: 3, styles: PosStyles(align: PosAlign.right)),
|
||||
// ]);
|
||||
// bytes += ticket.row([
|
||||
// PosColumn(text: '1', width: 1),
|
||||
// PosColumn(text: 'PIZZA', width: 7),
|
||||
// PosColumn(
|
||||
// text: '3.45', width: 2, styles: PosStyles(align: PosAlign.right)),
|
||||
// PosColumn(
|
||||
// text: '3.45', width: 2, styles: PosStyles(align: PosAlign.right)),
|
||||
// ]);
|
||||
// bytes += ticket.row([
|
||||
// PosColumn(text: '1', width: 1),
|
||||
// PosColumn(text: 'SPRING ROLLS', width: 7),
|
||||
// PosColumn(
|
||||
// text: '2.99', width: 2, styles: PosStyles(align: PosAlign.right)),
|
||||
// PosColumn(
|
||||
// text: '2.99', width: 2, styles: PosStyles(align: PosAlign.right)),
|
||||
// ]);
|
||||
// bytes += ticket.row([
|
||||
// PosColumn(text: '3', width: 1),
|
||||
// PosColumn(text: 'CRUNCHY STICKS', width: 7),
|
||||
// PosColumn(
|
||||
// text: '0.85', width: 2, styles: PosStyles(align: PosAlign.right)),
|
||||
// PosColumn(
|
||||
// text: '2.55', width: 2, styles: PosStyles(align: PosAlign.right)),
|
||||
// ]);
|
||||
// bytes += ticket.hr();
|
||||
|
||||
// bytes += ticket.row([
|
||||
// PosColumn(
|
||||
// text: 'TOTAL',
|
||||
// width: 6,
|
||||
// styles: PosStyles(
|
||||
// height: PosTextSize.size2,
|
||||
// width: PosTextSize.size2,
|
||||
// )),
|
||||
// PosColumn(
|
||||
// text: '\$10.97',
|
||||
// width: 6,
|
||||
// styles: PosStyles(
|
||||
// align: PosAlign.right,
|
||||
// height: PosTextSize.size2,
|
||||
// width: PosTextSize.size2,
|
||||
// )),
|
||||
// ]);
|
||||
|
||||
// bytes += ticket.hr(ch: '=', linesAfter: 1);
|
||||
|
||||
// bytes += ticket.row([
|
||||
// PosColumn(
|
||||
// text: 'CASH',
|
||||
// width: 7,
|
||||
// styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
|
||||
// PosColumn(
|
||||
// text: '\$15.00',
|
||||
// width: 5,
|
||||
// styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
|
||||
// ]);
|
||||
// bytes += ticket.row([
|
||||
// PosColumn(
|
||||
// text: 'CHANGE',
|
||||
// width: 7,
|
||||
// styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
|
||||
// PosColumn(
|
||||
// text: '\$4.03',
|
||||
// width: 5,
|
||||
// styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
|
||||
// ]);
|
||||
|
||||
// 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));
|
||||
|
||||
// final now = DateTime.now();
|
||||
// final formatter = DateFormat('MM/dd/yyyy H:m');
|
||||
// final String timestamp = formatter.format(now);
|
||||
// bytes += ticket.text(timestamp,
|
||||
// styles: PosStyles(align: PosAlign.center), linesAfter: 2);
|
||||
|
||||
//Print QR Code from image
|
||||
// try {
|
||||
// const String qrData = 'example.com';
|
||||
// const double qrSize = 100;
|
||||
// final uiImg = await QrPainter(
|
||||
// data: qrData,
|
||||
// version: QrVersions.auto,
|
||||
// gapless: false,
|
||||
// ).toImageData(qrSize);
|
||||
// final dir = await getTemporaryDirectory();
|
||||
// final pathName = '${dir.path}/qr_tmp.png';
|
||||
// final qrFile = File(pathName);
|
||||
// final imgFile = await qrFile.writeAsBytes(uiImg!.buffer.asUint8List());
|
||||
// final image = img.decodeImage(imgFile.readAsBytesSync());
|
||||
|
||||
// bytes += ticket.image(image!);
|
||||
// } catch (e) {
|
||||
// print(e);
|
||||
// }
|
||||
|
||||
// Print QR Code using native function
|
||||
// bytes += ticket.qrcode('example.com');
|
||||
|
||||
bytes += ticket.feed(1);
|
||||
bytes += ticket.cut();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
79
lib/theme/theme.config.dart
Normal file
79
lib/theme/theme.config.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
ThemeData theme({bool? useMaterial3}) {
|
||||
return ThemeData(
|
||||
useMaterial3: useMaterial3,
|
||||
scaffoldBackgroundColor: Colors.white,
|
||||
appBarTheme: appBarTheme(),
|
||||
textTheme: textTheme(),
|
||||
fontFamily: 'Nunito',
|
||||
inputDecorationTheme: inputDecorationTheme(),
|
||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||
textSelectionTheme: const TextSelectionThemeData(
|
||||
cursorColor: Color(0xFFFFC700),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Theme disableMaterial3({required Widget child}) {
|
||||
return Theme(data: theme(useMaterial3: false), child: child);
|
||||
}
|
||||
|
||||
Theme enableMaterial3({required Widget child}) {
|
||||
return Theme(data: theme(useMaterial3: true), child: child);
|
||||
}
|
||||
|
||||
AppBarTheme appBarTheme() {
|
||||
return const AppBarTheme(
|
||||
color: Colors.white,
|
||||
// backwardsCompatibility: false,
|
||||
systemOverlayStyle: SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.white,
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
),
|
||||
|
||||
surfaceTintColor: Colors.white,
|
||||
elevation: 0,
|
||||
// textTheme: TextTheme(
|
||||
// headline6: TextStyle(color: Color(0XFF8B8B8B), fontSize: 18),
|
||||
// ),
|
||||
);
|
||||
}
|
||||
|
||||
TextTheme textTheme() {
|
||||
return const TextTheme(
|
||||
bodyLarge: TextStyle(
|
||||
color: Color(0xFF0E0F0F),
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.normal,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
InputDecorationTheme inputDecorationTheme() {
|
||||
// OutlineInputBorder outlineInputBorder = OutlineInputBorder(
|
||||
// borderRadius: BorderRadius.circular(28),
|
||||
// borderSide: BorderSide(color: Pallete.textPrimary),
|
||||
// gapPadding: 10,
|
||||
// );
|
||||
|
||||
// return const InputDecorationTheme(
|
||||
// // If you are using latest version of flutter then lable text and hint text shown like this
|
||||
// // if you r using flutter less then 1.20.* then maybe this is not working properly
|
||||
// // if we are define our floatingLabelBehavior in our theme then it's not applayed
|
||||
// // floatingLabelBehavior: FloatingLabelBehavior.always,
|
||||
// // contentPadding: EdgeInsets.symmetric(horizontal: 42, vertical: 20),
|
||||
// // enabledBorder: outlineInputBorder,
|
||||
// // focusedBorder: outlineInputBorder,
|
||||
// // border: outlineInputBorder,
|
||||
// );
|
||||
|
||||
return const InputDecorationTheme(
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Color(0xFFFFC700), // Ganti dengan warna yang diinginkan
|
||||
width: 2, // Atur lebar border sesuai kebutuhan
|
||||
),
|
||||
borderRadius: BorderRadius.all(Radius.circular(8))));
|
||||
}
|
0
lib/utils.dart
Normal file
0
lib/utils.dart
Normal file
Reference in New Issue
Block a user