update redesign, add more option
This commit is contained in:
4
assets/image/ic_appbar_back.svg
Normal file
4
assets/image/ic_appbar_back.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg width="29" height="28" viewBox="0 0 29 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="14.8789" cy="14" r="14" fill="#F1F1F1"/>
|
||||
<path d="M17.5039 19.25L12.2539 14L17.5039 8.75" stroke="#333333" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
After Width: | Height: | Size: 290 B |
5
assets/image/ic_bluetooth.svg
Normal file
5
assets/image/ic_bluetooth.svg
Normal file
@@ -0,0 +1,5 @@
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M12.8999 10.5899L14.5699 9.05992L12.8999 7.66992V10.5899Z" fill="#292D32"/>
|
||||
<path d="M12.8999 16.3299L14.5699 14.9399L12.8999 13.4099V16.3299Z" fill="#292D32"/>
|
||||
<path d="M12 2C6.48 2 2 6.48 2 12C2 17.52 6.48 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2ZM15.72 13.95C16.01 14.22 16.17 14.59 16.16 14.97C16.15 15.35 15.97 15.72 15.67 15.97L13.6 17.7C13.22 18.02 12.87 18.11 12.6 18.11C12.38 18.11 12.21 18.05 12.11 18.01C11.89 17.91 11.39 17.58 11.39 16.67V14L9.09 16.11C8.79 16.39 8.31 16.37 8.03 16.06C7.75 15.75 7.77 15.28 8.08 15L11.36 12L8.08 8.99C7.78 8.71 7.76 8.24 8.04 7.93C8.32 7.63 8.8 7.6 9.1 7.88L11.4 10V7.33C11.4 6.43 11.9 6.1 12.12 5.99C12.33 5.89 12.91 5.72 13.61 6.29L15.67 8.01C15.97 8.26 16.15 8.63 16.16 9.01C16.17 9.39 16.01 9.77 15.72 10.03L13.58 12L15.72 13.95Z" fill="#292D32"/>
|
||||
</svg>
|
After Width: | Height: | Size: 923 B |
5
assets/image/ic_printer_bold.svg
Normal file
5
assets/image/ic_printer_bold.svg
Normal file
@@ -0,0 +1,5 @@
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M7 5C7 3.34 8.34 2 10 2H14C15.66 2 17 3.34 17 5C17 5.55 16.55 6 16 6H8C7.45 6 7 5.55 7 5Z" fill="#292D32"/>
|
||||
<path d="M17.75 15C17.75 15.41 17.41 15.75 17 15.75H16V19C16 20.66 14.66 22 13 22H11C9.34 22 8 20.66 8 19V15.75H7C6.59 15.75 6.25 15.41 6.25 15C6.25 14.59 6.59 14.25 7 14.25H17C17.41 14.25 17.75 14.59 17.75 15Z" fill="#292D32"/>
|
||||
<path d="M18 7H6C4 7 3 8 3 10V15C3 17 4 18 6 18H6.375C6.72018 18 7 17.7202 7 17.375C7 17.0298 6.71131 16.7604 6.38841 16.6384C5.72619 16.3882 5.25 15.7453 5.25 15C5.25 14.04 6.04 13.25 7 13.25H17C17.96 13.25 18.75 14.04 18.75 15C18.75 15.7453 18.2738 16.3882 17.6116 16.6384C17.2887 16.7604 17 17.0298 17 17.375C17 17.7202 17.2798 18 17.625 18H18C20 18 21 17 21 15V10C21 8 20 7 18 7ZM10 11.75H7C6.59 11.75 6.25 11.41 6.25 11C6.25 10.59 6.59 10.25 7 10.25H10C10.41 10.25 10.75 10.59 10.75 11C10.75 11.41 10.41 11.75 10 11.75Z" fill="#292D32"/>
|
||||
</svg>
|
After Width: | Height: | Size: 992 B |
7
assets/image/ic_printer_bulk.svg
Normal file
7
assets/image/ic_printer_bulk.svg
Normal file
@@ -0,0 +1,7 @@
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M16 15V19C16 20.66 14.66 22 13 22H11C9.34 22 8 20.66 8 19V15H16Z" fill="#292D32"/>
|
||||
<path d="M7 7V5C7 3.34 8.34 2 10 2H14C15.66 2 17 3.34 17 5V7H7Z" fill="#292D32"/>
|
||||
<path opacity="0.4" d="M18 7H6C4 7 3 8 3 10V15C3 17 4 18 6 18H8V15H16V18H18C20 18 21 17 21 15V10C21 8 20 7 18 7ZM10 11.75H7C6.59 11.75 6.25 11.41 6.25 11C6.25 10.59 6.59 10.25 7 10.25H10C10.41 10.25 10.75 10.59 10.75 11C10.75 11.41 10.41 11.75 10 11.75Z" fill="#292D32"/>
|
||||
<path d="M10.75 11C10.75 11.41 10.41 11.75 10 11.75H7C6.59 11.75 6.25 11.41 6.25 11C6.25 10.59 6.59 10.25 7 10.25H10C10.41 10.25 10.75 10.59 10.75 11Z" fill="#292D32"/>
|
||||
<path d="M17 15.75H7C6.59 15.75 6.25 15.41 6.25 15C6.25 14.59 6.59 14.25 7 14.25H17C17.41 14.25 17.75 14.59 17.75 15C17.75 15.41 17.41 15.75 17 15.75Z" fill="#292D32"/>
|
||||
</svg>
|
After Width: | Height: | Size: 887 B |
@@ -3,6 +3,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';
|
||||
import 'package:max_print_plus/print/max_print_bt.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
@@ -54,16 +55,21 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
child: Text('Click me')),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_printReceiveTest(true);
|
||||
_printReceiveTest(false);
|
||||
},
|
||||
child: Text('Print page mode')),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_printReceiveTest(true);
|
||||
},
|
||||
child: Text('Print page single mode')),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
Future _printReceiveTest(bool isPage) async {
|
||||
Future _printReceiveTest(bool isSinglePage) async {
|
||||
List<int> bytes = [];
|
||||
|
||||
// Xprinter XP-N160I
|
||||
@@ -259,13 +265,24 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
bytes += generator.text('TERIMA KASIH',
|
||||
styles: const PosStyles(align: PosAlign.center));
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MaxPrint(
|
||||
bytes: bytes,
|
||||
generator: generator,
|
||||
)));
|
||||
if (isSinglePage) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MaxPrintBt(
|
||||
bytes: bytes,
|
||||
generator: generator,
|
||||
onSuccess: (p0) {},
|
||||
)));
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MaxPrint(
|
||||
bytes: bytes,
|
||||
generator: generator,
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
// _showPrintDialog(List<int> bytes, Generator generator) {
|
||||
|
@@ -1,448 +0,0 @@
|
||||
// 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),
|
||||
// )
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
// }
|
@@ -1,6 +1,8 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:drago_pos_printer/drago_pos_printer.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:max_print_plus/widget/my_button.dart';
|
||||
// import 'package:webcontent_converter/demo.dart';
|
||||
// import 'package:webcontent_converter/webcontent_converter.dart';
|
||||
import '../service/service.dart';
|
||||
@@ -8,9 +10,15 @@ import '../service/service.dart';
|
||||
class BluetoothPrinterScreen extends StatefulWidget {
|
||||
List<int> bytes;
|
||||
EscGenerator generator;
|
||||
|
||||
BluetoothPrinterScreen(
|
||||
{super.key, required this.bytes, required this.generator});
|
||||
Function(bool)? onSuccess;
|
||||
bool? hideOption;
|
||||
BluetoothPrinterScreen({
|
||||
super.key,
|
||||
required this.bytes,
|
||||
required this.generator,
|
||||
this.onSuccess,
|
||||
this.hideOption = true,
|
||||
});
|
||||
|
||||
@override
|
||||
_BluetoothPrinterScreenState createState() => _BluetoothPrinterScreenState();
|
||||
@@ -43,41 +51,42 @@ class _BluetoothPrinterScreenState extends State<BluetoothPrinterScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xFFFAFAFA),
|
||||
backgroundColor: const Color(0xFFFAFAFA),
|
||||
body: ListView(
|
||||
padding: EdgeInsets.all(20),
|
||||
padding: const 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;
|
||||
if (!widget.hideOption!)
|
||||
DropdownButtonHideUnderline(
|
||||
child: DropdownButtonFormField(
|
||||
decoration: const 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(() {});
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
if (showCustom)
|
||||
Row(
|
||||
children: [
|
||||
@@ -87,41 +96,92 @@ class _BluetoothPrinterScreenState extends State<BluetoothPrinterScreen> {
|
||||
onChanged: (val) {
|
||||
if (val.isNotEmpty) {
|
||||
paperWidth = int.parse(val);
|
||||
} else
|
||||
} else {
|
||||
paperWidth = 0;
|
||||
}
|
||||
},
|
||||
)),
|
||||
SizedBox(width: 20),
|
||||
const SizedBox(width: 20),
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
initialValue: charPerLine.toString(),
|
||||
onChanged: (val) {
|
||||
if (val.isNotEmpty) {
|
||||
charPerLine = int.parse(val);
|
||||
} else
|
||||
} else {
|
||||
charPerLine = 0;
|
||||
}
|
||||
},
|
||||
))
|
||||
],
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
if (!widget.hideOption!) const SizedBox(height: 10),
|
||||
if (_printers.isEmpty)
|
||||
Container(
|
||||
padding: const EdgeInsets.only(top: 100),
|
||||
child: Column(
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
'assets/image/ic_printer_bulk.svg',
|
||||
width: 200,
|
||||
height: 200,
|
||||
package: 'max_print_plus',
|
||||
color: const Color.fromARGB(255, 207, 216, 220),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
const Text(
|
||||
'Bluetooth Kosong',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 20,
|
||||
color: Color.fromARGB(255, 186, 197, 202),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
..._printers
|
||||
.map((printer) => ListTile(
|
||||
title: Text("${printer.name}"),
|
||||
subtitle: Text("${printer.address}"),
|
||||
leading: Icon(Icons.bluetooth),
|
||||
title: Text(
|
||||
"${printer.name}",
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 15),
|
||||
),
|
||||
selectedColor: Colors.green,
|
||||
subtitle: Text("${printer.address}",
|
||||
style: const TextStyle(color: Colors.black)),
|
||||
leading: SvgPicture.asset(
|
||||
'assets/image/ic_bluetooth.svg',
|
||||
width: 30,
|
||||
height: 30,
|
||||
package: 'max_print_plus',
|
||||
color: printer.connected ? Colors.green : Colors.grey,
|
||||
),
|
||||
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)),
|
||||
tooltip: 'ESC POS Command',
|
||||
onPressed: () => _startPrinter(1, printer),
|
||||
icon: SvgPicture.asset(
|
||||
'assets/image/ic_printer_bold.svg',
|
||||
width: 28,
|
||||
height: 28,
|
||||
package: 'max_print_plus',
|
||||
color: printer.connected
|
||||
? Colors.green
|
||||
: Colors.grey,
|
||||
),
|
||||
),
|
||||
// IconButton(
|
||||
// tooltip: 'Html Print',
|
||||
// onPressed: () => _startPrinter(3, printer),
|
||||
// icon: const Icon(Icons.image)),
|
||||
],
|
||||
)
|
||||
: null,
|
||||
@@ -130,9 +190,14 @@ class _BluetoothPrinterScreenState extends State<BluetoothPrinterScreen> {
|
||||
.toList(),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: _isLoading ? Icon(Icons.stop) : Icon(Icons.play_arrow),
|
||||
onPressed: _isLoading ? null : _scan,
|
||||
bottomNavigationBar: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: MyButton(
|
||||
text: 'Refresh',
|
||||
textColor: Colors.black,
|
||||
press: _isLoading ? null : _scan,
|
||||
width: double.infinity,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -165,37 +230,21 @@ class _BluetoothPrinterScreenState extends State<BluetoothPrinterScreen> {
|
||||
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,
|
||||
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();
|
||||
|
||||
// Uint8List? htmlBytes = await WebcontentConverter.contentToImage(
|
||||
// content: content,
|
||||
// executablePath: WebViewHelper.executablePath(),
|
||||
// );
|
||||
|
||||
// var service = ESCPrinterService(htmlBytes);
|
||||
// data = await service.getBytes(
|
||||
// paperSizeWidthMM: paperWidth,
|
||||
// maxPerLine: charPerLine,
|
||||
// profile: profile);
|
||||
}
|
||||
// late List<int> data;
|
||||
// if (byteType == 1) {
|
||||
List<int> data = await ESCPrinterService(null).getSamplePosBytes(
|
||||
paperSizeWidthMM: paperWidth,
|
||||
maxPerLine: charPerLine,
|
||||
profile: profile,
|
||||
bytesData: widget.bytes,
|
||||
);
|
||||
|
||||
if (_manager != null) {
|
||||
if (!await _manager!.checkConnected()) await _manager!.connect();
|
||||
_manager!.writeBytes(data, isDisconnect: true);
|
||||
}
|
||||
|
||||
// widget.onSuccess!(true);
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
}
|
||||
|
62
lib/print/max_print_bt.dart
Normal file
62
lib/print/max_print_bt.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'package:drago_pos_printer/utils/esc_pos/generator.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:max_print_plus/print/bluetooth_printer_screen.dart';
|
||||
|
||||
enum HistoryTabData { reservation, dinein, waitinglist, pickup, delivery }
|
||||
|
||||
class MaxPrintBt extends StatefulWidget {
|
||||
List<int> bytes;
|
||||
EscGenerator generator;
|
||||
Function(bool)? onSuccess;
|
||||
bool? hideOption;
|
||||
MaxPrintBt(
|
||||
{Key? key,
|
||||
required this.bytes,
|
||||
required this.generator,
|
||||
required this.onSuccess,
|
||||
this.hideOption = true})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
State<MaxPrintBt> createState() => _MaxPrintBtState();
|
||||
}
|
||||
|
||||
class _MaxPrintBtState extends State<MaxPrintBt> with TickerProviderStateMixin {
|
||||
String? uid;
|
||||
bool? isLogin;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFFAFAFA),
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
icon: SvgPicture.asset(
|
||||
'assets/image/ic_appbar_back.svg',
|
||||
width: 30,
|
||||
height: 30,
|
||||
package: 'max_print_plus',
|
||||
)),
|
||||
backgroundColor: const Color(0xFFFAFAFA),
|
||||
centerTitle: true,
|
||||
title: const Text(
|
||||
'Cetak',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
// letterSpacing: 2.0,
|
||||
fontSize: 16),
|
||||
),
|
||||
),
|
||||
body: BluetoothPrinterScreen(
|
||||
bytes: widget.bytes, generator: widget.generator),
|
||||
);
|
||||
}
|
||||
}
|
@@ -34,28 +34,28 @@ class MyButton extends StatelessWidget {
|
||||
child: ElevatedButton(
|
||||
onPressed: press,
|
||||
style: ButtonStyle(
|
||||
elevation: MaterialStateProperty.all(0),
|
||||
padding: MaterialStateProperty.all(
|
||||
elevation: WidgetStateProperty.all(0),
|
||||
padding: WidgetStateProperty.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);
|
||||
backgroundColor: WidgetStateProperty.resolveWith<Color>(
|
||||
(Set<WidgetState> states) {
|
||||
if (states.contains(WidgetState.pressed)) {
|
||||
return const Color(0xFFDCDEE0);
|
||||
} else if (states.contains(WidgetState.disabled)) {
|
||||
return const Color(0xFFF2F2F5);
|
||||
} else if (states.contains(WidgetState.focused)) {
|
||||
return const Color(0xFFFFC700);
|
||||
}
|
||||
return color ??
|
||||
Color(0xFFFFC700); // Use the component's default.
|
||||
const Color(0xFFFFC700); // Use the component's default.
|
||||
},
|
||||
),
|
||||
textStyle: MaterialStateProperty.all<TextStyle>(
|
||||
TextStyle(color: textColor ?? Color(0xFF242632))),
|
||||
shape: MaterialStateProperty.resolveWith<RoundedRectangleBorder>(
|
||||
textStyle: WidgetStateProperty.all<TextStyle>(
|
||||
TextStyle(color: textColor ?? const Color(0xFF242632))),
|
||||
shape: WidgetStateProperty.resolveWith<RoundedRectangleBorder>(
|
||||
(states) {
|
||||
return RoundedRectangleBorder(
|
||||
side: !(states.contains(MaterialState.pressed))
|
||||
side: !(states.contains(WidgetState.pressed))
|
||||
? BorderSide(color: borderColor ?? Colors.transparent)
|
||||
: const BorderSide(color: Colors.transparent),
|
||||
borderRadius:
|
@@ -46,7 +46,8 @@ flutter:
|
||||
pluginClass: MaxPrintPlusPlugin
|
||||
ios:
|
||||
pluginClass: MaxPrintPlusPlugin
|
||||
|
||||
assets:
|
||||
- assets/image/
|
||||
# To add assets to your plugin package, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
|
Reference in New Issue
Block a user