Commit f6abf11b authored by Andrey's avatar Andrey

Added printer test

parent 41b53946
......@@ -9,7 +9,7 @@ It can be used in [Flutter](https://flutter.dev/) or pure [Dart](https://dart.de
To scan for printers in your network, consider using [ping_discover_network](https://pub.dev/packages/ping_discover_network) package. Note that most of the ESC/POS printers by default listen on port 9100.
## Tested Printers
Here are some [printers tested with this library](printers.md). Please add your models you have tested to maintain and improve this library and help others to choose the right printer.
Here are some [printers tested with this library](printers.md). Please add the models you have tested to maintain and improve this library and help others to choose the right printer.
......
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/material.dart' hide Image;
import 'package:esc_pos_printer/esc_pos_printer.dart';
......@@ -88,8 +89,8 @@ class _MyHomePageState extends State<MyHomePage> {
});
}
Future<Ticket> testTicket() async {
final Ticket ticket = Ticket(PaperSize.mm80);
Future<Ticket> demoTicket(PaperSize paper) async {
final Ticket ticket = Ticket(paper);
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');
......@@ -157,12 +158,156 @@ class _MyHomePageState extends State<MyHomePage> {
return ticket;
}
Ticket testPrinter1(PaperSize paper) {
final Ticket ticket = Ticket(paper);
ticket.text('Test 1. Text Styles, Code Tables & Positions',
styles: PosStyles(align: PosAlign.center), linesAfter: 2);
ticket.text('Regular: Hello world!');
ticket.text('westEur: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ blåbærgrød',
styles: PosStyles(codeTable: PosCodeTable.westEur));
ticket.text('Bold text', styles: PosStyles(bold: true));
ticket.text('Reverse text', styles: PosStyles(reverse: true));
ticket.text('Underlined text',
styles: PosStyles(underline: true), linesAfter: 1);
ticket.text('Align left', styles: PosStyles(align: PosAlign.left));
ticket.text('Align center', styles: PosStyles(align: PosAlign.center));
ticket.text('Align right',
styles: PosStyles(align: PosAlign.right), linesAfter: 1);
ticket.row([
PosColumn(
text: 'col3',
width: 3,
styles: PosStyles(align: PosAlign.center, underline: true),
),
PosColumn(
text: 'col6',
width: 6,
styles: PosStyles(align: PosAlign.center, underline: true),
),
PosColumn(
text: 'col3',
width: 3,
styles: PosStyles(align: PosAlign.center, underline: true),
),
]);
ticket.text('Text size 200%',
styles: PosStyles(
height: PosTextSize.size2,
width: PosTextSize.size2,
align: PosAlign.center,
));
ticket.feed(3);
ticket.cut();
return ticket;
}
Future<Ticket> testPrinter2_1(PaperSize paper) async {
final Ticket ticket = Ticket(paper);
ticket.text('Test 2. Images',
styles: PosStyles(align: PosAlign.center), linesAfter: 2);
// Print image
final ByteData data = await rootBundle.load('assets/logo.png');
final Uint8List bytes = data.buffer.asUint8List();
final Image image = decodeImage(bytes);
ticket.text('Command: ESC *');
ticket.image(image);
ticket.feed(2);
return ticket;
}
Future<Ticket> testPrinter2_2(PaperSize paper) async {
final Ticket ticket = Ticket(paper);
// Print image
final ByteData data = await rootBundle.load('assets/logo.png');
final Uint8List bytes = data.buffer.asUint8List();
final Image image = decodeImage(bytes);
ticket.text('Command: GS v 0');
ticket.imageRaster(image, imageFn: PosImageFn.bitImageRaster);
ticket.feed(2);
return ticket;
}
Future<Ticket> testPrinter2_3(PaperSize paper) async {
final Ticket ticket = Ticket(paper);
// Print image
final ByteData data = await rootBundle.load('assets/logo.png');
final Uint8List bytes = data.buffer.asUint8List();
final Image image = decodeImage(bytes);
ticket.text('Command: GS ( L');
ticket.imageRaster(image, imageFn: PosImageFn.graphics);
ticket.feed(3);
ticket.cut();
return ticket;
}
Ticket testPrinter3(PaperSize paper) {
final Ticket ticket = Ticket(paper);
ticket.text('Test 3. Barcode UPC-A',
styles: PosStyles(align: PosAlign.center), linesAfter: 2);
// Print barcode
final List<int> barData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 4];
ticket.barcode(Barcode.upcA(barData));
ticket.feed(3);
ticket.cut();
return ticket;
}
void testPrint(String printerIp, BuildContext ctx) async {
final PrinterNetworkManager printerManager = PrinterNetworkManager();
printerManager.selectPrinter(printerIp, port: 9100);
// TODO Don't forget to choose printer's paper
const PaperSize paper = PaperSize.mm80;
// Demo ticket
final PosPrintResult res =
await printerManager.printTicket(await testTicket());
await printerManager.printTicket(await demoTicket(paper));
// TODO Comment the above printTicket line and uncomment those to run a more complete test.
// Don't forget to add your results here (WIFI/Network): https://github.com/andrey-ushakov/esc_pos_printer/blob/master/printers.md
// or here (Bluetooth): https://github.com/andrey-ushakov/esc_pos_bluetooth/blob/master/printers.md
// NOTE: If your printer can't handle all tests together, you can run them individually
// TEST PRINTER - START
// Test1 - Texts
// await printerManager.printTicket(testPrinter1(paper));
// sleep(Duration(seconds: 3));
// Test2 - Images (3 commands)
// await printerManager.printTicket(await testPrinter2_1(paper));
// sleep(Duration(seconds: 3));
// await printerManager.printTicket(await testPrinter2_2(paper));
// sleep(Duration(seconds: 3));
// await printerManager.printTicket(await testPrinter2_3(paper));
// sleep(Duration(seconds: 3));
// Test3 - Barcode
// final PosPrintResult res =
// await printerManager.printTicket(testPrinter3(paper));
// sleep(Duration(seconds: 3));
// TEST PRINTER - END
final snackBar =
SnackBar(content: Text(res.msg, textAlign: TextAlign.center));
Scaffold.of(ctx).showSnackBar(snackBar);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment