elgin 0.2.1 elgin: ^0.2.1 copied to clipboard
Este package tem como finalidade a comunicação de um jeito fácil com vários equipamentos elgin, como SAT, impressoras térmicas e mini PDVs
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:elgin/elgin.dart';
import 'package:esc_pos_utils_plus/esc_pos_utils_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Sunmi Printer',
theme: ThemeData(
primaryColor: Colors.black,
),
debugShowCheckedModeBanner: false,
home: const Home());
}
}
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
bool printBinded = false;
String url = 'http://marcus.brasizza.com/imagens/flutter-icon.png';
String printerVersion = "";
@override
void initState() {
super.initState();
}
Future<int?> startPrinter(ElginPrinter driver) async {
try {
final int? result = await Elgin.printer.connect(driver: driver);
setState(() {
printBinded = result == 0 ? true : false;
});
if (result == 0) {
String version = await Elgin.printer.libVersion;
setState(() {
printerVersion = version;
});
}
return result;
} on ElginException catch (e) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(e.error.message)));
return null;
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('ELGIN printer Example'),
),
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(
top: 10,
),
child: Text("Print binded: " + printBinded.toString()),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 2.0),
child: Text("Printer version: " + printerVersion),
),
const Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
final _driver =
ElginPrinter(type: ElginPrinterType.MINIPDV);
await startPrinter(_driver);
},
child: const Text('Start M8/M10 printer')),
ElevatedButton(
onPressed: () async {
final _driver = ElginPrinter(
type: ElginPrinterType.TCP,
model: ElginPrinterModel.GENERIC_TCP,
connection: '192.168.5.111',
parameter: 9100,
);
await startPrinter(_driver);
},
child: const Text(
'Start TCP/IP Printer (change IP in example)')),
ElevatedButton(
onPressed: () async {
final _driver = ElginPrinter(
type: ElginPrinterType.USB,
model: ElginPrinterModel.MP2800,
connection: 'USB',
parameter: 115200,
);
await startPrinter(_driver);
},
child: const Text('USB PRINTER')),
ElevatedButton(
onPressed: () async {
final _driver = ElginPrinter(
type: ElginPrinterType.BLUETHOOTH,
model: ElginPrinterModel.SMARTPOS,
connection: 'F4:5E:AB:D9:6C:3F',
parameter: 0,
);
await startPrinter(_driver);
},
child: const Text('BLUETOOTH PRINTER')),
],
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.printQRCode(
"https://github.com/brasizza/flutter-elgin",
size: ElginQrcodeSize.SIZE5,
align: ElginAlign.CENTER,
);
await Elgin.printer.feed(2);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Print qrCode')),
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.printBarCode(
'{C35170900246872000134590002121801051011580881',
barcodeType: EliginBarcodeType.CODE128,
textPosition: ElginBarcodeTextPosition.TEXT_UNDER,
align: ElginAlign.CENTER,
height: 100,
width: 3,
);
await Elgin.printer.feed(2);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Print barCode')),
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.line();
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Print line')),
ElevatedButton(
onPressed: () async {
await Elgin.printer.feed(2);
},
child: const Text('Wrap line')),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer
.printString('Hello I\'m bold', isBold: true);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Bold Text')),
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.printString('Normal font',
fontSize: ElginSize.MD);
await Elgin.printer.feed(2);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Normal font')),
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.printString('Large font',
fontSize: ElginSize.LG);
await Elgin.printer.feed(2);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Large font')),
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.printString('Very large font',
fontSize: ElginSize.XL);
await Elgin.printer.feed(2);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Very large font')),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.printString('Algin right',
align: ElginAlign.RIGHT);
await Elgin.printer.feed(2);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Align right')),
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.printString('Algin left',
align: ElginAlign.RIGHT);
await Elgin.printer.feed(2);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Align left')),
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.printString(
'Align center/ LARGE TEXT AND BOLD',
align: ElginAlign.CENTER,
isBold: true,
fontSize: ElginSize.XL,
isUnderline: true);
await Elgin.printer.feed(2);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Align center'),
),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
GestureDetector(
onTap: () async {
Uint8List byte =
await _getImageFromAsset('assets/images/dash.jpeg');
Directory tempPath = await getTemporaryDirectory();
File file = File('${tempPath.path}/dash.jpg');
await file.writeAsBytes(byte.buffer
.asUint8List(byte.offsetInBytes, byte.lengthInBytes));
try {
await Elgin.printer.printImage(file, false);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: Column(
children: [
Image.asset(
'assets/images/dash.jpeg',
width: 100,
),
const Text('Print this image from asset!')
],
),
),
GestureDetector(
onTap: () async {
// convert image to Uint8List format
Uint8List byte =
(await NetworkAssetBundle(Uri.parse(url)).load(url))
.buffer
.asUint8List();
Directory tempPath = await getTemporaryDirectory();
File file = File('${tempPath.path}/onlineImage.jpg');
await file.writeAsBytes(byte.buffer
.asUint8List(byte.offsetInBytes, byte.lengthInBytes));
try {
await Elgin.printer.printImage(file, false);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: Column(
children: [
Image.network(
url,
width: 100,
),
const Text('Print this image from WEB!')
],
),
),
],
),
),
const Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.cut();
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('CUT PAPER')),
]),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
try {
final List<int> _escPos = await _customEscPos();
await Elgin.printer.printRaw(_escPos);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Custom ESC/POS to print')),
]),
),
],
),
const Divider(),
Text("Sensors"),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
try {
int _sensor =
await Elgin.printer.statusSensor();
String messageSensor = 'Sensor is OK';
if (_sensor == 6) {
messageSensor = 'Paper is running out!';
}
if (_sensor == 7) {
messageSensor = 'No paper!';
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(messageSensor)));
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Paper sensor')),
]),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.elginCashier();
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Elgin cashier')),
]),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.customCashier(1, 2, 3);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Custom cashier')),
]),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
try {
await Elgin.printer.beep(5, 10, 20);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('Beep')),
]),
),
],
),
const Divider(),
Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
String xmlSAT =
'<?xml version="1.0"?><CFe><infCFe versaoDadosEnt="0.07"><ide><CNPJ>08427847000169</CNPJ><signAC>SGR-SAT SISTEMA DE GESTAO E RETAGUARDA DO SAT</signAC><numeroCaixa>001</numeroCaixa></ide><emit><CNPJ>61099008000141</CNPJ><IE>111111111111</IE><IM>12345</IM><cRegTribISSQN>3</cRegTribISSQN><indRatISSQN>N</indRatISSQN></emit><dest/><det nItem="1"><prod><cProd>116</cProd><cEAN>9990000001163</cEAN><xProd>Cascao</xProd><CFOP>5405</CFOP><uCom>UN</uCom><qCom>1.0000</qCom><vUnCom>4.00</vUnCom><indRegra>A</indRegra></prod><imposto><ICMS><ICMSSN102><Orig>0</Orig><CSOSN>500</CSOSN></ICMSSN102></ICMS><PIS><PISSN><CST>49</CST></PISSN></PIS><COFINS><COFINSSN><CST>49</CST></COFINSSN></COFINS></imposto></det><total/><pgto><MP><cMP>01</cMP><vMP>4.00</vMP></MP></pgto></infCFe></CFe>';
try {
await Elgin.printer.printSAT(xmlSAT);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('PRINT SAT XML')),
]),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
String csc = '123';
int cscId = 000;
String xmlNFCE =
'<?xml version="1.0"?><NFe xmlns="http://www.portalfiscal.inf.br/nfe"><infNFe Id="NFe51231126713774000153650020001628771855038849" versao="4.00"><ide><cUF>51</cUF><cNF>85503884</cNF><natOp>5102</natOp><mod>65</mod><serie>2</serie><nNF>162877</nNF><dhEmi>2023-11-09T00:38:07-03:00</dhEmi><tpNF>1</tpNF><idDest>1</idDest><cMunFG>5107602</cMunFG><tpImp>4</tpImp><tpEmis>1</tpEmis><cDV>9</cDV><tpAmb>1</tpAmb><finNFe>1</finNFe><indFinal>1</indFinal><indPres>1</indPres><indIntermed>0</indIntermed><procEmi>0</procEmi><verProc>3.0.0</verProc></ide><emit><CNPJ>26713774000153</CNPJ><xNome>MHD RESTAURANTE E PUB LTDA</xNome><xFant>Draft American Pub</xFant><enderEmit><xLgr>Avenida Governador Julio Jose de Campos</xLgr><nro>2088</nro><xBairro>Parque Sagrada Familia</xBairro><cMun>5107602</cMun><xMun>Rondonopolis</xMun><UF>MT</UF><CEP>78735330</CEP><cPais>1058</cPais><xPais>Brasil</xPais><fone>669669966</fone></enderEmit><IE>136618456</IE><CRT>2</CRT></emit><dest><CPF>02358631140</CPF><xNome>Wesley Junior Santos Pereira</xNome><indIEDest>9</indIEDest></dest><det nItem="1"><prod><cProd>1078</cProd><cEAN>SEM GTIN</cEAN><xProd>AGUA FREE</xProd><NCM>22011000</NCM><CEST>0000000</CEST><indEscala>S</indEscala><CFOP>5405</CFOP><uCom>UN</uCom><qCom>1.0000</qCom><vUnCom>0.0100000000</vUnCom><vProd>0.01</vProd><cEANTrib>SEM GTIN</cEANTrib><uTrib>UN</uTrib><qTrib>1.0000</qTrib><vUnTrib>0.0100000000</vUnTrib><vDesc>2.00</vDesc><indTot>1</indTot><nItemPed>1</nItemPed></prod><imposto><vTotTrib>0.00</vTotTrib><ICMS><ICMS60><orig>0</orig><CST>60</CST><vBCSTRet>0.00</vBCSTRet><pST>0.0000</pST><vICMSSTRet>0.00</vICMSSTRet></ICMS60></ICMS><PIS><PISNT><CST>08</CST></PISNT></PIS><COFINS><COFINSNT><CST>08</CST></COFINSNT></COFINS></imposto></det><det nItem="2"><prod><cProd>1184</cProd><cEAN>SEM GTIN</cEAN><xProd>OLD PARR GOLD DS</xProd><NCM>22083020</NCM><CEST>0000000</CEST><indEscala>S</indEscala><CFOP>5405</CFOP><uCom>UN</uCom><qCom>1.0000</qCom><vUnCom>26.0000000000</vUnCom><vProd>26.00</vProd><cEANTrib>SEM GTIN</cEANTrib><uTrib>UN</uTrib><qTrib>1.0000</qTrib><vUnTrib>26.0000000000</vUnTrib><vDesc>0.01</vDesc><indTot>1</indTot><nItemPed>2</nItemPed></prod><imposto><vTotTrib>0.00</vTotTrib><ICMS><ICMS60><orig>0</orig><CST>60</CST><vBCSTRet>0.00</vBCSTRet><pST>0.0000</pST><vICMSSTRet>0.00</vICMSSTRet></ICMS60></ICMS><PIS><PISNT><CST>08</CST></PISNT></PIS><COFINS><COFINSNT><CST>08</CST></COFINSNT></COFINS></imposto></det><det nItem="3"><prod><cProd>1237</cProd><cEAN>SEM GTIN</cEAN><xProd>RED BULL</xProd><NCM>22029100</NCM><CEST>0000000</CEST><indEscala>S</indEscala><CFOP>5405</CFOP><uCom>UN</uCom><qCom>1.0000</qCom><vUnCom>16.0000000000</vUnCom><vProd>16.00</vProd><cEANTrib>SEM GTIN</cEANTrib><uTrib>UN</uTrib><qTrib>1.0000</qTrib><vUnTrib>16.0000000000</vUnTrib><indTot>1</indTot><nItemPed>3</nItemPed></prod><imposto><vTotTrib>0.00</vTotTrib><ICMS><ICMS60><orig>0</orig><CST>60</CST><vBCSTRet>0.00</vBCSTRet><pST>0.0000</pST><vICMSSTRet>0.00</vICMSSTRet></ICMS60></ICMS><PIS><PISNT><CST>08</CST></PISNT></PIS><COFINS><COFINSNT><CST>08</CST></COFINSNT></COFINS></imposto></det><det nItem="4"><prod><cProd>1240</cProd><cEAN>SEM GTIN</cEAN><xProd>Gorjeta concedida</xProd><NCM>00000000</NCM><CEST>0000000</CEST><indEscala>S</indEscala><CFOP>5102</CFOP><uCom>UN</uCom><qCom>1.0000</qCom><vUnCom>4.2000000000</vUnCom><vProd>4.20</vProd><cEANTrib>SEM GTIN</cEANTrib><uTrib>UN</uTrib><qTrib>1.0000</qTrib><vUnTrib>4.2000000000</vUnTrib><indTot>1</indTot><nItemPed>4</nItemPed></prod><imposto><vTotTrib>0.71</vTotTrib><ICMS><ICMS00><orig>0</orig><CST>00</CST><modBC>3</modBC><vBC>4.20</vBC><pICMS>17.0000</pICMS><vICMS>0.71</vICMS></ICMS00></ICMS><PIS><PISNT><CST>08</CST></PISNT></PIS><COFINS><COFINSNT><CST>08</CST></COFINSNT></COFINS></imposto></det><total><ICMSTot><vBC>4.20</vBC><vICMS>0.71</vICMS><vICMSDeson>0.00</vICMSDeson><vFCP>0.00</vFCP><vBCST>0.00</vBCST><vST>0.00</vST><vFCPST>0.00</vFCPST><vFCPSTRet>0.00</vFCPSTRet><vProd>46.21</vProd><vFrete>0.00</vFrete><vSeg>0.00</vSeg><vDesc>2.01</vDesc><vII>0.00</vII><vIPI>0.00</vIPI><vIPIDevol>0.00</vIPIDevol><vPIS>0.00</vPIS><vCOFINS>0.00</vCOFINS><vOutro>0.00</vOutro><vNF>44.20</vNF><vTotTrib>0.71</vTotTrib></ICMSTot></total><transp><modFrete>9</modFrete></transp><pag><detPag><tPag>01</tPag><vPag>44.20</vPag></detPag></pag><infAdic><infCpl>- :Nacional: R 0,00 Estadual: R 0,00 Municipal: R 0,00 Importado: R F:231249</infCpl></infAdic><infRespTec><CNPJ>15120049000155</CNPJ><xContato>OZTECHNOLOGY</xContato><email>develop@oztechnology.com.br</email><fone>1138928272</fone></infRespTec></infNFe><infNFeSupl><qrCode>http://www.sefaz.mt.gov.br/nfce/consultanfce?p=51231126713774000153650020001628771855038849|2|1|1|6544C4CFEC6C922725DDE354FF2778EF8E5F63A5</qrCode><urlChave>http://www.sefaz.mt.gov.br/nfce/consultanfce</urlChave></infNFeSupl><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI="#NFe51231126713774000153650020001628771855038849"><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>zqXAf7EF/9hGc74PoWhpLa43Z9o=</DigestValue></Reference></SignedInfo><SignatureValue>fqKpxSFhEsI0jBmra8yxGnP+ZaPY27WA4au0dhwOQTIH3xItmVGpfNxDT9oZp4F7YydahVzHlfTYq8+9B5inflXPzVVx+0MPr0/l7RGycQrzBVHxUUZSTPBeUClGO2qwlRof9TdaGYNLlnwOgBywCxlRs+bjq1uPp7fHeRsFr/FmaLP7xAA/57vX5TTU0goItzAN2j6VI2ik71ryFV7pjFrM7o8FCxJY1xOoMpsknTnKMPr9g6c9do2MQh+KtltXDpyvNTlu0WTtbUOpeMsq3ilCpCJsuxbYzmqkRW30bcriUy4MCil9h6R4ilTR1AkwaIqFRuaOLWv7ujZBadWwiQ==</SignatureValue><KeyInfo><X509Data><X509Certificate>MIIIjzCCBnegAwIBAgIIY1DAyjyOwAcwDQYJKoZIhvcNAQELBQAwYDELMAkGA1UEBhMCQlIxEzARBgNVBAoTCklDUC1CcmFzaWwxEzARBgNVBAsTCkFDIFNBRkVXRUIxJzAlBgNVBAMTHkFDIE1FVEEgQ0VSVElGSUNBRE8gRElHSVRBTCBDRDAeFw0yMjEyMDEyMTQzMjZaFw0yMzEyMDEyMTQzMjZaMIHuMQswCQYDVQQGEwJCUjETMBEGA1UEChMKSUNQLUJyYXNpbDEnMCUGA1UECxMeQUMgTUVUQSBDRVJUSUZJQ0FETyBESUdJVEFMIENEMSkwJwYDVQQLEyBNRVRBIENFUlRJRklDQURPIERJR0lUQUwgZS1QSiBBMTEXMBUGA1UECxMOMjI0MjgwMjYwMDAxNz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sGPD/Pk3stbSlR5avZNXC7PGGfrRgEzasF5/olMKMgyJYm5U7YqYx31f9yzuGT9aOkHkWo2sX+8m4I/X2EdvqDKzdGAy5tVo15t9cgFOhcCoC1EeOuObBBepj4A3x8A7zILrjq8WzIpgyYBRDYkI8iW2sXwlkV2DHkJR4apKcc1LlC/lG26oI9xwxZDVdkQvcbvNAUj2dWjk67jlqu6SYrJTilLMf9r9rGEXVnxBqCZ9iHpZHomRpvABLOoxQWiS3Yqc3AuQGUBshxigytd1eOdiFo6Gbns7563sDgFa9PyJFH59qSE8KXuP+kF66EStks3NRwLvApyCEd1sEFo+La6umHbFmPKd+/i9tcgTY0H7Yn53D73vyzxHoSnaiNXXLk=</X509Certificate></X509Data></KeyInfo></Signature></NFe>';
try {
await Elgin.printer
.printNFCE(xmlNFCE, csc, cscId, param: 4);
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('PRINT NFCE XML')),
]),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
String cupomTef =
'ICAgICAgICAgICAgICAgICBSRURFCiAgICAgICAgIE1BU1RFUkNBUkQgREVCSVRPICAgICAgICAgTApDT01QUk9WOiAxMjM0NTY3ODk5IFZBTE9SOiAgICAgICAgNDQsMDcKRVNUQUI6MTIzMzMzMyBFU1RBQkVMRUNJTUVOVE8gVEVTVEUgTFREQQpDTlBKL0NQRjoxMS4xMTEuMTExLzAwMDEtMTEKMDcuMTEuMjEtMjI6MTM6MDIgVEVSTTpQVjYzOTczMi8wMDAyNTMKQ0FSVEFPOiB4eHh4eHh4eHh4eHg5OTk5CkFVVE9SSVpBQ0FPOiAzMjE2NzcKQVJRQzpCRjZGM0IxN0RENTFDRDBBCkFJRDogQTAwMDAwMDAwNDQ0NDQ0CiAgICBUUkFOU0FDQU8gQVBST1ZBREEgUEVMTyBFTUlTU09SCgoKCgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKFNpVGVmKQo=';
try {
await Elgin.printer.printTEF(
utf8.decode(base64.decode(cupomTef)));
} on ElginException catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.error.message)));
}
},
child: const Text('PRINT TEF BASE64')),
]),
),
],
),
],
),
),
);
}
}
Future<Uint8List> readFileBytes(String path) async {
ByteData fileData = await rootBundle.load(path);
Uint8List fileUnit8List = fileData.buffer
.asUint8List(fileData.offsetInBytes, fileData.lengthInBytes);
return fileUnit8List;
}
Future<Uint8List> _getImageFromAsset(String iconPath) async {
return await readFileBytes(iconPath);
}
Future<List<int>> _customEscPos() async {
final profile = await CapabilityProfile.load();
final generator = Generator(PaperSize.mm58, profile);
List<int> bytes = [];
bytes += generator.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 += generator.text('Bold text', styles: const PosStyles(bold: true));
bytes +=
generator.text('Reverse text', styles: const PosStyles(reverse: true));
bytes += generator.text('Underlined text',
styles: const PosStyles(underline: true), linesAfter: 1);
bytes += generator.text('Align left',
styles: const PosStyles(align: PosAlign.left));
bytes += generator.text('Align center',
styles: const PosStyles(align: PosAlign.center));
bytes += generator.text('Align right',
styles: const PosStyles(align: PosAlign.right), linesAfter: 1);
bytes += generator.qrcode('Barcode by escpos',
size: QRSize.Size4, cor: QRCorrection.H);
bytes += generator.feed(2);
bytes += generator.row([
PosColumn(
text: 'col3',
width: 3,
styles: const PosStyles(align: PosAlign.center, underline: true),
),
PosColumn(
text: 'col6',
width: 6,
styles: const PosStyles(align: PosAlign.center, underline: true),
),
PosColumn(
text: 'col3',
width: 3,
styles: const PosStyles(align: PosAlign.center, underline: true),
),
]);
bytes += generator.text('Text size 200%',
styles: const PosStyles(
height: PosTextSize.size2,
width: PosTextSize.size2,
));
bytes += generator.reset();
return bytes;
}