Created
August 9, 2022 04:18
-
-
Save brasizza/9d23402f1d678917dc28494ef2b13807 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:esc_pos_utils/esc_pos_utils.dart'; | |
import 'package:get/get.dart'; | |
import 'package:viapp_totem/app/core/printers/elgin_printer_device.dart'; | |
import 'package:viapp_totem/app/core/printers/physical_printer.dart'; | |
import 'package:viapp_totem/app/core/printers/network_printer.dart'; | |
import 'package:viapp_totem/app/core/printers/sunmi_printer.dart'; | |
class GeneralPrinterContorller extends GetxController { | |
PhysicalPrinter get physical => PhysicalPrinter.instance; | |
NetWorkPrint get network => NetWorkPrint.instance; | |
SunmiPrinterDevice get sunmi => SunmiPrinterDevice.instance; | |
ElginPrinterDevice get elgin => ElginPrinterDevice.instance; | |
var _printerInstance; | |
T printerInstance<T>() { | |
return _printerInstance as T; | |
} | |
T? printer<T>(Map<String, dynamic>? printer) { | |
if (printer?['impressora'] == null) { | |
_printerInstance = null; // null; physical as T; | |
return null; | |
} else { | |
if (printer?['impressora']['fabricante'] == 'M8_M10') { | |
_printerInstance = elgin as T; | |
return elgin as T; | |
} | |
if (printer?['impressora']['fabricante'] == 'SUNMI_50' || printer?['impressora']['fabricante'] == 'SUNMI_80') { | |
if (printer?['impressora']['fabricante'] == 'SUNMI_50') { | |
sunmi.paper = PaperSize.mm58; | |
} | |
_printerInstance = sunmi as T; | |
return sunmi as T; | |
} | |
if (printer?['impressora']['local_device'] != null && printer?['impressora']['local_device'] != '') { | |
physical.devicePort = printer?['impressora']['local_device']; | |
_printerInstance = physical as T; | |
return physical as T; | |
} else { | |
if (printer?['impressora']['impressora_rede'] != null && printer?['impressora']['impressora_rede'] != '') { | |
if (printer?['impressora']['porta_rede'] == "" || printer?['impressora']['porta_rede'] == null) { | |
network.port = 9100; | |
} else { | |
try { | |
network.port = int.parse(printer?['impressora']['porta_rede']); | |
} catch (_) { | |
network.port = 9100; | |
} | |
} | |
network.ip = printer?['impressora']['impressora_rede']; | |
_printerInstance = network as T; | |
return network as T; | |
} else { | |
_printerInstance = physical as T; | |
return physical as T; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment