Commit 1e426dcd authored by Andrey's avatar Andrey

Added demo receipt example

parent 2c7d3782
PODS:
- Flutter (1.0.0)
- path_provider (0.0.1):
- Flutter
- path_provider_macos (0.0.1):
- Flutter
- wifi (0.0.1):
- Flutter
DEPENDENCIES:
- Flutter (from `Flutter`)
- path_provider (from `.symlinks/plugins/path_provider/ios`)
- path_provider_macos (from `.symlinks/plugins/path_provider_macos/ios`)
- wifi (from `.symlinks/plugins/wifi/ios`)
EXTERNAL SOURCES:
Flutter:
:path: Flutter
path_provider:
:path: ".symlinks/plugins/path_provider/ios"
path_provider_macos:
:path: ".symlinks/plugins/path_provider_macos/ios"
wifi:
:path: ".symlinks/plugins/wifi/ios"
SPEC CHECKSUMS:
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
path_provider: fb74bd0465e96b594bb3b5088ee4a4e7bb1f2a9d
path_provider_macos: f760a3c5b04357c380e2fddb6f9db6f3015897e0
wifi: d7d77c94109e36c4175d845f0a5964eadba71060
PODFILE CHECKSUM: 1b66dae606f75376c5f2135a8290850eeb09ae83
......
import 'dart:io';
import 'dart:typed_data';
import 'package:intl/intl.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/material.dart' hide Image;
import 'package:esc_pos_printer/esc_pos_printer.dart';
import 'package:flutter/services.dart';
......@@ -89,7 +92,7 @@ class _MyHomePageState extends State<MyHomePage> {
});
}
Future<Ticket> demoTicket(PaperSize paper) async {
Future<Ticket> testTicket(PaperSize paper) async {
final Ticket ticket = Ticket(paper);
ticket.text(
......@@ -158,116 +161,145 @@ 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);
Future<Ticket> demoReceipt80mm() async {
final Ticket ticket = Ticket(PaperSize.mm80);
// Print image
final ByteData data = await rootBundle.load('assets/logo.png');
final ByteData data = await rootBundle.load('assets/rabbit_black.jpg');
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.text('GROCERYLY',
styles: PosStyles(
align: PosAlign.center,
height: PosTextSize.size2,
width: PosTextSize.size2,
),
linesAfter: 1);
ticket.feed(2);
return ticket;
}
ticket.text('889 Watson Lane', styles: PosStyles(align: PosAlign.center));
ticket.text('New Braunfels, TX', styles: PosStyles(align: PosAlign.center));
ticket.text('Tel: 830-221-1234', styles: PosStyles(align: PosAlign.center));
ticket.text('Web: www.example.com',
styles: PosStyles(align: PosAlign.center), linesAfter: 1);
Future<Ticket> testPrinter2_3(PaperSize paper) async {
final Ticket ticket = Ticket(paper);
ticket.text('------------------------------------------------');
ticket.row([
PosColumn(text: 'Qty', width: 1),
PosColumn(text: 'Item', width: 7),
PosColumn(
text: 'Price', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(
text: 'Total', width: 2, styles: PosStyles(align: PosAlign.right)),
]);
// Print image
final ByteData data = await rootBundle.load('assets/logo.png');
final Uint8List bytes = data.buffer.asUint8List();
final Image image = decodeImage(bytes);
ticket.row([
PosColumn(text: '2', width: 1),
PosColumn(text: 'ONION RINGS', width: 7),
PosColumn(
text: '0.99', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(
text: '1.98', width: 2, styles: PosStyles(align: PosAlign.right)),
]);
ticket.row([
PosColumn(text: '1', width: 1),
PosColumn(text: 'PIZZA', width: 7),
PosColumn(
text: '3.45', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(
text: '3.45', width: 2, styles: PosStyles(align: PosAlign.right)),
]);
ticket.row([
PosColumn(text: '1', width: 1),
PosColumn(text: 'SPRING ROLLS', width: 7),
PosColumn(
text: '2.99', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(
text: '2.99', width: 2, styles: PosStyles(align: PosAlign.right)),
]);
ticket.row([
PosColumn(text: '3', width: 1),
PosColumn(text: 'CRUNCHY STICKS', width: 7),
PosColumn(
text: '0.85', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(
text: '2.55', width: 2, styles: PosStyles(align: PosAlign.right)),
]);
ticket.text('------------------------------------------------');
ticket.text('Command: GS ( L');
ticket.imageRaster(image, imageFn: PosImageFn.graphics);
ticket.row([
PosColumn(
text: 'TOTAL',
width: 6,
styles: PosStyles(
height: PosTextSize.size2,
width: PosTextSize.size2,
)),
PosColumn(
text: '\$10.97',
width: 6,
styles: PosStyles(
align: PosAlign.right,
height: PosTextSize.size2,
width: PosTextSize.size2,
)),
]);
ticket.text('------------------------------------------------',
linesAfter: 1);
ticket.feed(3);
ticket.cut();
return ticket;
}
ticket.row([
PosColumn(
text: 'Cash',
width: 8,
styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
PosColumn(
text: '\$15.00',
width: 4,
styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
]);
ticket.row([
PosColumn(
text: 'Change',
width: 8,
styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
PosColumn(
text: '\$4.03',
width: 4,
styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
]);
Ticket testPrinter3(PaperSize paper) {
final Ticket ticket = Ticket(paper);
ticket.feed(2);
ticket.text('Thank you!',
styles: PosStyles(align: PosAlign.center, bold: true));
ticket.text('Test 3. Barcode UPC-A',
final now = DateTime.now();
final formatter = DateFormat('MM/dd/yyyy H:m');
final String timestamp = formatter.format(now);
ticket.text(timestamp,
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));
try {
const String qrData = 'example.com';
const double qrSize = 200;
final uiImg = await QrPainter(
data: qrData,
version: QrVersions.auto,
gapless: false,
).toImageData(qrSize);
final dir = await getTemporaryDirectory();
final pathName = '${dir.path}/qr_tmp.png';
final qrFile = File(pathName);
final imgFile = await qrFile.writeAsBytes(uiImg.buffer.asUint8List());
final img = decodeImage(imgFile.readAsBytesSync());
ticket.image(img);
} catch (e) {
print(e);
}
ticket.feed(3);
ticket.feed(2);
ticket.cut();
return ticket;
}
......@@ -275,38 +307,14 @@ class _MyHomePageState extends State<MyHomePage> {
final PrinterNetworkManager printerManager = PrinterNetworkManager();
printerManager.selectPrinter(printerIp, port: 9100);
// TODO Don't forget to choose printer's paper
const PaperSize paper = PaperSize.mm80;
// TEST PRINT
// const PaperSize paper = PaperSize.mm80; // TODO Don't forget to choose printer's paper
// final PosPrintResult res =
// await printerManager.printTicket(await testTicket(paper));
// Demo ticket
// DEMMO RECEIPT
final PosPrintResult res =
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
await printerManager.printTicket(await demoReceipt80mm());
final snackBar =
SnackBar(content: Text(res.msg, textAlign: TextAlign.center));
......
......@@ -15,6 +15,9 @@ dependencies:
image: ^2.1.4
esc_pos_printer:
path: ../../
intl: ^0.16.1
qr_flutter: ^3.2.0
path_provider: ^1.6.5
esc_pos_utils: ^0.3.3
# esc_pos_utils:
# path: ../../../esc_pos_utils
......@@ -27,4 +30,5 @@ dev_dependencies:
flutter:
uses-material-design: true
assets:
- assets/logo.png
\ No newline at end of file
- assets/logo.png
- assets/rabbit_black.jpg
\ No newline at end of file
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