tracking print
This commit is contained in:
parent
e1e702bd76
commit
a6ac12c36a
@ -12,6 +12,7 @@ import 'package:enaklo_pos/data/datasources/settings_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
|
||||
import 'package:enaklo_pos/data/type/bussines_type.dart';
|
||||
import 'package:enaklo_pos/presentation/home/models/product_quantity.dart';
|
||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:barcode/barcode.dart';
|
||||
import 'package:image/image.dart' as img;
|
||||
@ -54,8 +55,17 @@ Future<void> onPrint(
|
||||
// ignore: use_build_context_synchronously
|
||||
.printWithPrinter(checkerPrinter, printValue, context);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e, stackTrace) {
|
||||
log("Error printing checker: $e");
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Error printing checker ${checkerPrinter.name}',
|
||||
information: [
|
||||
'Printer: checker',
|
||||
'data: ${checkerPrinter.toMap()}',
|
||||
],
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Error printing checker: $e')),
|
||||
);
|
||||
@ -82,8 +92,17 @@ Future<void> onPrint(
|
||||
await PrinterService()
|
||||
.printWithPrinter(kitchenPrinter, printValue, context);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e, stackTrace) {
|
||||
log("Error printing kitchen order: $e");
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Error printing kitchen ${kitchenPrinter.name}',
|
||||
information: [
|
||||
'Printer: kitchen',
|
||||
'data: ${kitchenPrinter.toMap()}',
|
||||
],
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Error printing kitchen order: $e')),
|
||||
);
|
||||
@ -111,8 +130,17 @@ Future<void> onPrint(
|
||||
await PrinterService()
|
||||
.printWithPrinter(barPrinter, printValue, context);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e, stackTrace) {
|
||||
log("Error printing bar order: $e");
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Error printing bar ${barPrinter.name}',
|
||||
information: [
|
||||
'Printer: bar',
|
||||
'data: ${barPrinter.toMap()}',
|
||||
],
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Error printing bar order: $e')),
|
||||
);
|
||||
@ -137,7 +165,16 @@ Future<void> onPrint(
|
||||
await PrinterService()
|
||||
// ignore: use_build_context_synchronously
|
||||
.printWithPrinter(ticketPrinter, printValue, context);
|
||||
} catch (e) {
|
||||
} catch (e, stackTrace) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Error printing ticket ${ticketPrinter.name}',
|
||||
information: [
|
||||
'Printer: ticket',
|
||||
'data: ${ticketPrinter.toMap()}',
|
||||
],
|
||||
);
|
||||
log("Error printing ticket: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Error printing ticket: $e')),
|
||||
@ -176,7 +213,17 @@ Future<void> onPrintRecipt(
|
||||
productQuantity);
|
||||
await PrinterService()
|
||||
.printWithPrinter(receiptPrinter, printValue, context);
|
||||
} catch (e) {
|
||||
} catch (e, stackTrace) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Print receipt failed',
|
||||
information: [
|
||||
'Order ID: ${order.id}',
|
||||
'Payment Method: $paymentMethod',
|
||||
'Printer: ${receiptPrinter.name}',
|
||||
],
|
||||
);
|
||||
log("Error printing receipt order: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Error printing receipt order: $e')),
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import 'dart:developer';
|
||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_esc_pos_network/flutter_esc_pos_network.dart';
|
||||
import 'package:print_bluetooth_thermal/print_bluetooth_thermal.dart';
|
||||
@ -20,17 +21,36 @@ class PrinterService {
|
||||
}
|
||||
|
||||
// Connect to the printer
|
||||
bool connected = await PrintBluetoothThermal.connect(
|
||||
macPrinterAddress: macAddress);
|
||||
|
||||
bool connected =
|
||||
await PrintBluetoothThermal.connect(macPrinterAddress: macAddress);
|
||||
|
||||
if (connected) {
|
||||
log("Successfully connected to Bluetooth printer: $macAddress");
|
||||
} else {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Failed to connect to Bluetooth printer',
|
||||
null,
|
||||
reason: 'Failed to connect to Bluetooth printe',
|
||||
information: [
|
||||
'function: connectBluetoothPrinter(String macAddress)',
|
||||
'macAddress: $macAddress',
|
||||
],
|
||||
);
|
||||
log("Failed to connect to Bluetooth printer: $macAddress");
|
||||
}
|
||||
|
||||
|
||||
return connected;
|
||||
} catch (e) {
|
||||
} catch (e, stackTrace) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Error connecting to Bluetooth printer',
|
||||
information: [
|
||||
'function: connectBluetoothPrinter(String macAddress)',
|
||||
'Printer: Bluetooth printer',
|
||||
'macAddress: $macAddress',
|
||||
],
|
||||
);
|
||||
log("Error connecting to Bluetooth printer: $e");
|
||||
return false;
|
||||
}
|
||||
@ -49,11 +69,30 @@ class PrinterService {
|
||||
if (printResult) {
|
||||
log("Successfully printed via Bluetooth");
|
||||
} else {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Failed to print via Bluetooth',
|
||||
null,
|
||||
reason: 'Failed to print via Bluetooth',
|
||||
information: [
|
||||
'function: printBluetooth(List<int> printData)',
|
||||
'printData: $printData',
|
||||
],
|
||||
);
|
||||
log("Failed to print via Bluetooth");
|
||||
}
|
||||
|
||||
|
||||
return printResult;
|
||||
} catch (e) {
|
||||
} catch (e, stackTrace) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Error printing via Bluetooth',
|
||||
information: [
|
||||
'function: printBluetooth(List<int> printData)',
|
||||
'Printer: Bluetooth printer',
|
||||
'printData: $printData',
|
||||
],
|
||||
);
|
||||
log("Error printing via Bluetooth: $e");
|
||||
return false;
|
||||
}
|
||||
@ -64,42 +103,94 @@ class PrinterService {
|
||||
try {
|
||||
final printer = PrinterNetworkManager(ipAddress);
|
||||
PosPrintResult connect = await printer.connect();
|
||||
|
||||
|
||||
if (connect == PosPrintResult.success) {
|
||||
PosPrintResult printing = await printer.printTicket(printData);
|
||||
printer.disconnect();
|
||||
|
||||
|
||||
if (printing == PosPrintResult.success) {
|
||||
log("Successfully printed via Network printer: $ipAddress");
|
||||
return true;
|
||||
} else {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Failed to print via Network printer: ${printing.msg}',
|
||||
null,
|
||||
reason: 'Failed to print via Network printer',
|
||||
information: [
|
||||
'function: printNetwork(String ipAddress, List<int> printData)',
|
||||
'Printer: Network printer',
|
||||
'ipAddress: $ipAddress',
|
||||
'printData: $printData',
|
||||
],
|
||||
);
|
||||
log("Failed to print via Network printer: ${printing.msg}");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Failed to connect to Network printer: ${connect.msg}',
|
||||
null,
|
||||
reason: 'Failed to connectNetwork printer',
|
||||
information: [
|
||||
'function: printNetwork(String ipAddress, List<int> printData)',
|
||||
'Printer: Network printer',
|
||||
'ipAddress: $ipAddress',
|
||||
'printData: $printData',
|
||||
],
|
||||
);
|
||||
log("Failed to connect to Network printer: ${connect.msg}");
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e, stackTrace) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Error printing via Network',
|
||||
information: [
|
||||
'function: printNetwork(String ipAddress, List<int> printData)',
|
||||
'Printer: Network printer',
|
||||
'ipAddress: $ipAddress',
|
||||
'printData: $printData',
|
||||
],
|
||||
);
|
||||
log("Error printing via Network: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Print with automatic printer type detection
|
||||
Future<bool> printWithPrinter(PrintModel printer, List<int> printData, BuildContext context) async {
|
||||
Future<bool> printWithPrinter(
|
||||
PrintModel printer, List<int> printData, BuildContext context) async {
|
||||
try {
|
||||
if (printer.type == 'Bluetooth') {
|
||||
bool connected = await connectBluetoothPrinter(printer.address);
|
||||
if (!connected) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Failed to connect to Bluetooth printer',
|
||||
null,
|
||||
reason: 'Failed to connect to Bluetooth printe',
|
||||
information: [
|
||||
'function: connectBluetoothPrinter(String macAddress)',
|
||||
'Printer: ${printer.name}',
|
||||
'macAddress: ${printer.address}',
|
||||
],
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Failed to connect to ${printer.name}')),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool printResult = await printBluetooth(printData);
|
||||
if (!printResult) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Failed to print to ${printer.name}',
|
||||
null,
|
||||
information: [
|
||||
'function: await printBluetooth(printData);',
|
||||
'print: $printData',
|
||||
],
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Failed to print to ${printer.name}')),
|
||||
);
|
||||
@ -108,13 +199,32 @@ class PrinterService {
|
||||
} else {
|
||||
bool printResult = await printNetwork(printer.address, printData);
|
||||
if (!printResult) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Failed to connect to Network Printer',
|
||||
null,
|
||||
reason: 'Failed to connect to Network Printer',
|
||||
information: [
|
||||
'function: await printNetwork(printer.address, printData);',
|
||||
'Printer: ${printer.name}',
|
||||
'ipAddress: ${printer.address}',
|
||||
'print: $printData',
|
||||
],
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Failed to print to ${printer.name}')),
|
||||
);
|
||||
}
|
||||
return printResult;
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e, stackTrace) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Error printing with printer ${printer.name}',
|
||||
information: [
|
||||
'Printer: ${printer.name}',
|
||||
],
|
||||
);
|
||||
log("Error printing with printer ${printer.name}: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Error printing to ${printer.name}: $e')),
|
||||
@ -154,4 +264,4 @@ class PrinterService {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user