Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
esc_pos_print_plus
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dio Maulana
esc_pos_print_plus
Commits
78cbb375
Commit
78cbb375
authored
Jan 16, 2020
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added PrinterNetworkManager. Updated examples.
parent
6fb75107
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
257 additions
and
687 deletions
+257
-687
.flutter-plugins-dependencies
example/discover_printers/.flutter-plugins-dependencies
+1
-0
Flutter.podspec
example/discover_printers/ios/Flutter/Flutter.podspec
+18
-0
flutter_export_environment.sh
...scover_printers/ios/Flutter/flutter_export_environment.sh
+2
-1
Podfile.lock
example/discover_printers/ios/Podfile.lock
+8
-2
main.dart
example/discover_printers/lib/main.dart
+78
-59
pubspec.yaml
example/discover_printers/pubspec.yaml
+1
-1
example.dart
example/example.dart
+75
-59
esc_pos_printer.dart
lib/esc_pos_printer.dart
+1
-1
enums.dart
lib/src/enums.dart
+23
-0
printer.dart
lib/src/printer.dart
+0
-560
printer_bluetooth_manager.dart
lib/src/printer_bluetooth_manager.dart
+1
-4
printer_network_manager.dart
lib/src/printer_network_manager.dart
+49
-0
No files found.
example/discover_printers/.flutter-plugins-dependencies
0 → 100644
View file @
78cbb375
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_bluetooth_basic","dependencies":[]},{"name":"wifi","dependencies":[]}]}
\ No newline at end of file
example/discover_printers/ios/Flutter/Flutter.podspec
0 → 100644
View file @
78cbb375
#
# NOTE: This podspec is NOT to be published. It is only used as a local source!
#
Pod
::
Spec
.
new
do
|
s
|
s
.
name
=
'Flutter'
s
.
version
=
'1.0.0'
s
.
summary
=
'High-performance, high-fidelity mobile apps.'
s
.
description
=
<<-
DESC
Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS.
DESC
s
.
homepage
=
'https://flutter.io'
s
.
license
=
{
:type
=>
'MIT'
}
s
.
author
=
{
'Flutter Dev Team'
=>
'flutter-dev@googlegroups.com'
}
s
.
source
=
{
:git
=>
'https://github.com/flutter/engine'
,
:tag
=>
s
.
version
.
to_s
}
s
.
ios
.
deployment_target
=
'8.0'
s
.
vendored_frameworks
=
'Flutter.framework'
end
example/discover_printers/ios/Flutter/flutter_export_environment.sh
View file @
78cbb375
...
@@ -2,9 +2,10 @@
...
@@ -2,9 +2,10 @@
# This is a generated file; do not edit or check into version control.
# This is a generated file; do not edit or check into version control.
export
"FLUTTER_ROOT=/Users/andrey/Documents/flutter"
export
"FLUTTER_ROOT=/Users/andrey/Documents/flutter"
export
"FLUTTER_APPLICATION_PATH=/Users/andrey/Documents/Tablemi_v2/esc_pos_printer/example/discover_printers"
export
"FLUTTER_APPLICATION_PATH=/Users/andrey/Documents/Tablemi_v2/esc_pos_printer/example/discover_printers"
export
"FLUTTER_TARGET=lib/main.dart"
export
"FLUTTER_TARGET=
/Users/andrey/Documents/Tablemi_v2/esc_pos_printer/example/discover_printers/
lib/main.dart"
export
"FLUTTER_BUILD_DIR=build"
export
"FLUTTER_BUILD_DIR=build"
export
"SYMROOT=
${
SOURCE_ROOT
}
/../build/ios"
export
"SYMROOT=
${
SOURCE_ROOT
}
/../build/ios"
export
"FLUTTER_FRAMEWORK_DIR=/Users/andrey/Documents/flutter/bin/cache/artifacts/engine/ios"
export
"FLUTTER_FRAMEWORK_DIR=/Users/andrey/Documents/flutter/bin/cache/artifacts/engine/ios"
export
"FLUTTER_BUILD_NAME=1.0.0"
export
"FLUTTER_BUILD_NAME=1.0.0"
export
"FLUTTER_BUILD_NUMBER=1"
export
"FLUTTER_BUILD_NUMBER=1"
export
"TRACK_WIDGET_CREATION=true"
example/discover_printers/ios/Podfile.lock
View file @
78cbb375
PODS:
PODS:
- Flutter (1.0.0)
- Flutter (1.0.0)
- flutter_bluetooth_basic (0.0.1):
- Flutter
- wifi (0.0.1):
- wifi (0.0.1):
- Flutter
- Flutter
DEPENDENCIES:
DEPENDENCIES:
- Flutter (from `.symlinks/flutter/ios`)
- Flutter (from `.symlinks/flutter/ios`)
- flutter_bluetooth_basic (from `.symlinks/plugins/flutter_bluetooth_basic/ios`)
- wifi (from `.symlinks/plugins/wifi/ios`)
- wifi (from `.symlinks/plugins/wifi/ios`)
EXTERNAL SOURCES:
EXTERNAL SOURCES:
Flutter:
Flutter:
:path: ".symlinks/flutter/ios"
:path: ".symlinks/flutter/ios"
flutter_bluetooth_basic:
:path: ".symlinks/plugins/flutter_bluetooth_basic/ios"
wifi:
wifi:
:path: ".symlinks/plugins/wifi/ios"
:path: ".symlinks/plugins/wifi/ios"
SPEC CHECKSUMS:
SPEC CHECKSUMS:
Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
flutter_bluetooth_basic: 0e4e27e22b50b3a25cc1d1e131953feb4af414f4
wifi: d7d77c94109e36c4175d845f0a5964eadba71060
wifi: d7d77c94109e36c4175d845f0a5964eadba71060
PODFILE CHECKSUM: aff02bfeed411c636180d6812254b2daeea14d09
PODFILE CHECKSUM: aff02bfeed411c636180d6812254b2daeea14d09
COCOAPODS: 1.
7.5
COCOAPODS: 1.
8.4
example/discover_printers/lib/main.dart
View file @
78cbb375
...
@@ -63,7 +63,7 @@ class _MyHomePageState extends State<MyHomePage> {
...
@@ -63,7 +63,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
}
print
(
'subnet:
\t
$subnet
, port:
\t
$port
'
);
print
(
'subnet:
\t
$subnet
, port:
\t
$port
'
);
final
stream
=
NetworkAnalyzer
.
discover
(
subnet
,
port
);
final
stream
=
NetworkAnalyzer
.
discover
2
(
subnet
,
port
);
stream
.
listen
((
NetworkAddress
addr
)
{
stream
.
listen
((
NetworkAddress
addr
)
{
if
(
addr
.
exists
)
{
if
(
addr
.
exists
)
{
...
@@ -87,23 +87,26 @@ class _MyHomePageState extends State<MyHomePage> {
...
@@ -87,23 +87,26 @@ class _MyHomePageState extends State<MyHomePage> {
});
});
}
}
void
testPrint
(
String
printerIp
,
BuildContext
ctx
)
{
Future
<
Ticket
>
testTicket
()
async
{
Printer
.
connect
(
printerIp
,
final
Ticket
ticket
=
Ticket
(
PaperSize
.
mm80
);
port:
int
.
parse
(
portController
.
text
),
timeout:
Duration
(
seconds:
5
))
.
then
((
printer
)
async
{
ticket
.
text
(
printer
.
println
(
'Normal 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'
);
printer
.
println
(
'Bold text'
,
styles:
PosStyles
(
bold:
true
));
ticket
.
text
(
'Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ'
,
printer
.
println
(
'Reverse text'
,
styles:
PosStyles
(
reverse:
true
));
styles:
PosStyles
(
codeTable:
PosCodeTable
.
westEur
));
printer
.
println
(
'Underlined text'
,
ticket
.
text
(
'Special 2: 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
);
styles:
PosStyles
(
underline:
true
),
linesAfter:
1
);
printer
.
println
(
'Align left'
,
ticket
.
text
(
'Align left'
,
styles:
PosStyles
(
align:
PosTextAlign
.
left
));
styles:
PosStyles
(
align:
PosTextAlign
.
left
));
ticket
.
text
(
'Align center'
,
styles:
PosStyles
(
align:
PosTextAlign
.
center
));
printer
.
println
(
'Align center'
,
ticket
.
text
(
'Align right'
,
styles:
PosStyles
(
align:
PosTextAlign
.
center
));
printer
.
println
(
'Align right'
,
styles:
PosStyles
(
align:
PosTextAlign
.
right
),
linesAfter:
1
);
styles:
PosStyles
(
align:
PosTextAlign
.
right
),
linesAfter:
1
);
printer
.
printR
ow
([
ticket
.
r
ow
([
PosColumn
(
PosColumn
(
text:
'col3'
,
text:
'col3'
,
width:
3
,
width:
3
,
...
@@ -121,7 +124,7 @@ class _MyHomePageState extends State<MyHomePage> {
...
@@ -121,7 +124,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
]);
]);
printer
.
println
(
'Text size 200%'
,
ticket
.
text
(
'Text size 200%'
,
styles:
PosStyles
(
styles:
PosStyles
(
height:
PosTextSize
.
size2
,
height:
PosTextSize
.
size2
,
width:
PosTextSize
.
size2
,
width:
PosTextSize
.
size2
,
...
@@ -131,20 +134,36 @@ class _MyHomePageState extends State<MyHomePage> {
...
@@ -131,20 +134,36 @@ class _MyHomePageState extends State<MyHomePage> {
final
ByteData
data
=
await
rootBundle
.
load
(
'assets/logo.png'
);
final
ByteData
data
=
await
rootBundle
.
load
(
'assets/logo.png'
);
final
Uint8List
bytes
=
data
.
buffer
.
asUint8List
();
final
Uint8List
bytes
=
data
.
buffer
.
asUint8List
();
final
Image
image
=
decodeImage
(
bytes
);
final
Image
image
=
decodeImage
(
bytes
);
printer
.
printImage
(
image
);
ticket
.
image
(
image
);
// Print image using an alternative (obsolette) command
// ticket.imageRaster(image);
printer
.
cut
();
// Print barcode
printer
.
disconnect
();
final
List
<
int
>
barData
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
0
,
4
];
ticket
.
barcode
(
Barcode
.
upcA
(
barData
));
final
snackBar
=
// Print mixed (chinese + latin) text. Only for printers supporting Kanji mode
SnackBar
(
content:
Text
(
'Success'
,
textAlign:
TextAlign
.
center
));
// ticket.text(
Scaffold
.
of
(
ctx
).
showSnackBar
(
snackBar
);
// 'hello ! 中文字 # world @ éphémère &',
}).
catchError
((
dynamic
e
)
{
// styles: PosStyles(codeTable: PosCodeTable.westEur),
print
(
'exception'
);
// containsChinese: true,
final
snackBar
=
// );
SnackBar
(
content:
Text
(
'Fail'
,
textAlign:
TextAlign
.
center
));
ticket
.
feed
(
2
);
ticket
.
cut
();
return
ticket
;
}
void
testPrint
(
String
printerIp
,
BuildContext
ctx
)
async
{
final
PrinterNetworkManager
printerManager
=
PrinterNetworkManager
();
printerManager
.
selectPrinter
(
printerIp
,
port:
9100
);
final
PosPrintResult
res
=
await
printerManager
.
printTicket
(
await
testTicket
());
final
snackBar
=
SnackBar
(
content:
Text
(
PosPrintResult
.
msg
(
res
),
textAlign:
TextAlign
.
center
));
Scaffold
.
of
(
ctx
).
showSnackBar
(
snackBar
);
Scaffold
.
of
(
ctx
).
showSnackBar
(
snackBar
);
});
}
}
@override
@override
...
...
example/discover_printers/pubspec.yaml
View file @
78cbb375
...
@@ -20,7 +20,7 @@ dependencies:
...
@@ -20,7 +20,7 @@ dependencies:
flutter
:
flutter
:
sdk
:
flutter
sdk
:
flutter
wifi
:
^0.1.5
wifi
:
^0.1.5
ping_discover_network
:
^0.
1.2
ping_discover_network
:
^0.
2.0+1
image
:
^2.1.4
image
:
^2.1.4
esc_pos_printer
:
esc_pos_printer
:
path
:
../../
path
:
../../
...
...
example/example.dart
View file @
78cbb375
import
'dart:io'
;
import
'dart:io'
;
import
'package:esc_pos_printer/esc_pos_printer.dart'
;
import
'dart:typed_data'
;
import
'package:flutter/services.dart'
;
import
'package:image/image.dart'
;
import
'package:image/image.dart'
;
import
'package:esc_pos_printer/esc_pos_printer.dart'
;
void
main
(
)
{
void
main
(
)
async
{
// To discover existing printers in your subnet, consider using
final
PrinterNetworkManager
printerManager
=
PrinterNetworkManager
();
// To discover network printers in your subnet, consider using
// ping_discover_network package (https://pub.dev/packages/ping_discover_network).
// ping_discover_network package (https://pub.dev/packages/ping_discover_network).
// Note that most of ESC/POS printers by default listen on port 9100.
// Note that most of ESC/POS printers are available on port 9100 by default.
Printer
.
connect
(
'192.168.0.123'
,
port:
9100
).
then
((
printer
)
{
printerManager
.
selectPrinter
(
'192.168.0.123'
,
port:
9100
);
printer
.
println
(
final
PosPrintResult
res
=
await
printerManager
.
printTicket
(
await
testTicket
());
print
(
'Print result:
${PosPrintResult.msg(res)}
'
);
}
Future
<
Ticket
>
testTicket
()
async
{
final
Ticket
ticket
=
Ticket
(
PaperSize
.
mm80
);
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'
);
'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'
);
printer
.
println
(
'Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ'
,
ticket
.
text
(
'Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ'
,
styles:
PosStyles
(
codeTable:
PosCodeTable
.
westEur
));
styles:
PosStyles
(
codeTable:
PosCodeTable
.
westEur
));
printer
.
println
(
'Special 2: blåbærgrød'
,
ticket
.
text
(
'Special 2: blåbærgrød'
,
styles:
PosStyles
(
codeTable:
PosCodeTable
.
westEur
));
styles:
PosStyles
(
codeTable:
PosCodeTable
.
westEur
));
printer
.
println
(
'Bold text'
,
styles:
PosStyles
(
bold:
true
));
ticket
.
text
(
'Bold text'
,
styles:
PosStyles
(
bold:
true
));
printer
.
println
(
'Reverse text'
,
styles:
PosStyles
(
reverse:
true
));
ticket
.
text
(
'Reverse text'
,
styles:
PosStyles
(
reverse:
true
));
printer
.
println
(
'Underlined text'
,
ticket
.
text
(
'Underlined text'
,
styles:
PosStyles
(
underline:
true
),
linesAfter:
1
);
styles:
PosStyles
(
underline:
true
),
linesAfter:
1
);
printer
.
println
(
'Align left'
,
styles:
PosStyles
(
align:
PosTextAlign
.
left
));
ticket
.
text
(
'Align left'
,
styles:
PosStyles
(
align:
PosTextAlign
.
left
));
printer
.
println
(
'Align center'
,
ticket
.
text
(
'Align center'
,
styles:
PosStyles
(
align:
PosTextAlign
.
center
));
styles:
PosStyles
(
align:
PosTextAlign
.
center
));
ticket
.
text
(
'Align right'
,
printer
.
println
(
'Align right'
,
styles:
PosStyles
(
align:
PosTextAlign
.
right
),
linesAfter:
1
);
styles:
PosStyles
(
align:
PosTextAlign
.
right
),
linesAfter:
1
);
printer
.
printRow
([
ticket
.
row
([
PosColumn
(
PosColumn
(
text:
'col3'
,
text:
'col3'
,
width:
3
,
width:
3
,
...
@@ -40,30 +52,34 @@ void main() {
...
@@ -40,30 +52,34 @@ void main() {
styles:
PosStyles
(
align:
PosTextAlign
.
center
,
underline:
true
),
styles:
PosStyles
(
align:
PosTextAlign
.
center
,
underline:
true
),
),
),
]);
]);
printer
.
println
(
'Text size 200%'
,
ticket
.
text
(
'Text size 200%'
,
styles:
PosStyles
(
styles:
PosStyles
(
height:
PosTextSize
.
size2
,
height:
PosTextSize
.
size2
,
width:
PosTextSize
.
size2
,
width:
PosTextSize
.
size2
,
));
));
// Print image
// Print image
const
String
filename
=
'./logo.png'
;
final
ByteData
data
=
await
rootBundle
.
load
(
'assets/logo.png'
);
final
Image
image
=
decodeImage
(
File
(
filename
).
readAsBytesSync
());
final
Uint8List
bytes
=
data
.
buffer
.
asUint8List
();
printer
.
printImage
(
image
);
final
Image
image
=
decodeImage
(
bytes
);
ticket
.
image
(
image
);
// Print image using an alternative (obsolette) command
// Print image using an alternative (obsolette) command
// printer.printI
mageRaster(image);
// ticket.i
mageRaster(image);
// Print barcode
// Print barcode
final
List
<
int
>
barData
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
0
,
4
];
final
List
<
int
>
barData
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
0
,
4
];
printer
.
printB
arcode
(
Barcode
.
upcA
(
barData
));
ticket
.
b
arcode
(
Barcode
.
upcA
(
barData
));
// Print mixed (chinese + latin) text. Only for printers supporting Kanji mode
// Print mixed (chinese + latin) text. Only for printers supporting Kanji mode
// printer.println
(
// ticket.text
(
// 'hello ! 中文字 # world @ éphémère &',
// 'hello ! 中文字 # world @ éphémère &',
// styles: PosStyles(codeTable: PosCodeTable.westEur),
// styles: PosStyles(codeTable: PosCodeTable.westEur),
// containsChinese: true,
// );
// );
printer
.
cut
();
ticket
.
feed
(
2
);
printer
.
disconnect
();
});
ticket
.
cut
();
return
ticket
;
}
}
lib/esc_pos_printer.dart
View file @
78cbb375
...
@@ -11,6 +11,6 @@ export './src/barcode.dart';
...
@@ -11,6 +11,6 @@ export './src/barcode.dart';
export
'./src/enums.dart'
;
export
'./src/enums.dart'
;
export
'./src/pos_column.dart'
;
export
'./src/pos_column.dart'
;
export
'./src/pos_styles.dart'
;
export
'./src/pos_styles.dart'
;
export
'./src/printer.dart'
;
export
'./src/printer_bluetooth_manager.dart'
;
export
'./src/printer_bluetooth_manager.dart'
;
export
'./src/printer_network_manager.dart'
;
export
'./src/ticket.dart'
;
export
'./src/ticket.dart'
;
lib/src/enums.dart
View file @
78cbb375
...
@@ -10,6 +10,29 @@ enum PosTextAlign { left, center, right }
...
@@ -10,6 +10,29 @@ enum PosTextAlign { left, center, right }
enum
PosCutMode
{
full
,
partial
}
enum
PosCutMode
{
full
,
partial
}
enum
PosFontType
{
fontA
,
fontB
}
enum
PosFontType
{
fontA
,
fontB
}
class
PosPrintResult
{
const
PosPrintResult
.
_internal
(
this
.
value
);
final
int
value
;
static
const
success
=
PosPrintResult
.
_internal
(
1
);
static
const
timeout
=
PosPrintResult
.
_internal
(
2
);
static
const
printerNotSelected
=
PosPrintResult
.
_internal
(
3
);
static
const
ticketEmpty
=
PosPrintResult
.
_internal
(
4
);
static
String
msg
(
PosPrintResult
val
)
{
if
(
val
==
PosPrintResult
.
success
)
{
return
'Success'
;
}
else
if
(
val
==
PosPrintResult
.
timeout
)
{
return
'Error. Printer connection timeout'
;
}
else
if
(
val
==
PosPrintResult
.
printerNotSelected
)
{
return
'Error. Printer not selected'
;
}
else
if
(
val
==
PosPrintResult
.
ticketEmpty
)
{
return
'Error. Ticket is empty'
;
}
else
{
return
'Unknown error'
;
}
}
}
class
PosTextSize
{
class
PosTextSize
{
const
PosTextSize
.
_internal
(
this
.
value
);
const
PosTextSize
.
_internal
(
this
.
value
);
final
int
value
;
final
int
value
;
...
...
lib/src/printer.dart
deleted
100644 → 0
View file @
6fb75107
This diff is collapsed.
Click to expand it.
lib/src/printer_bluetooth_manager.dart
View file @
78cbb375
...
@@ -94,7 +94,6 @@ class PrinterBluetoothManager {
...
@@ -94,7 +94,6 @@ class PrinterBluetoothManager {
_bluetoothManager
.
state
.
listen
((
state
)
async
{
_bluetoothManager
.
state
.
listen
((
state
)
async
{
switch
(
state
)
{
switch
(
state
)
{
case
BluetoothManager
.
CONNECTED
:
case
BluetoothManager
.
CONNECTED
:
// print('********************* CONNECTED');
// To avoid double call
// To avoid double call
if
(!
_isConnected
)
{
if
(!
_isConnected
)
{
await
_bluetoothManager
.
writeData
(
bytes
);
await
_bluetoothManager
.
writeData
(
bytes
);
...
@@ -102,14 +101,12 @@ class PrinterBluetoothManager {
...
@@ -102,14 +101,12 @@ class PrinterBluetoothManager {
}
}
// TODO sending disconnect signal should be event-based
// TODO sending disconnect signal should be event-based
_runDelayed
(
3
).
then
((
dynamic
v
)
async
{
_runDelayed
(
3
).
then
((
dynamic
v
)
async
{
// print('DISCONNECTING......');
await
_bluetoothManager
.
disconnect
();
await
_bluetoothManager
.
disconnect
();
_isPrinting
=
false
;
_isPrinting
=
false
;
});
});
_isConnected
=
true
;
_isConnected
=
true
;
break
;
break
;
case
BluetoothManager
.
DISCONNECTED
:
case
BluetoothManager
.
DISCONNECTED
:
// print('********************* DISCONNECTED');
_isConnected
=
false
;
_isConnected
=
false
;
break
;
break
;
default
:
default
:
...
@@ -127,7 +124,7 @@ class PrinterBluetoothManager {
...
@@ -127,7 +124,7 @@ class PrinterBluetoothManager {
}
}
Future
<
void
>
printTicket
(
Ticket
ticket
)
async
{
Future
<
void
>
printTicket
(
Ticket
ticket
)
async
{
if
(
ticket
.
bytes
.
isNotEmpty
)
{
if
(
ticket
!=
null
&&
ticket
.
bytes
.
isNotEmpty
)
{
final
Future
<
void
>
res
=
writeBytes
(
ticket
.
bytes
);
final
Future
<
void
>
res
=
writeBytes
(
ticket
.
bytes
);
return
res
;
return
res
;
}
else
{
}
else
{
...
...
lib/src/printer_network_manager.dart
0 → 100644
View file @
78cbb375
/*
* esc_pos_printer
* Created by Andrey Ushakov
*
* Copyright (c) 2019-2020. All rights reserved.
* See LICENSE for distribution and usage details.
*/
import
'dart:io'
;
import
'./enums.dart'
;
import
'./ticket.dart'
;
/// Printer Network Manager
class
PrinterNetworkManager
{
String
_host
;
int
_port
;
Duration
_timeout
;
/// Select a network printer
///
/// [timeout] is used to specify the maximum allowed time to wait
/// for a connection to be established.
void
selectPrinter
(
String
host
,
{
int
port
=
9100
,
Duration
timeout
=
const
Duration
(
seconds:
5
),
})
{
_host
=
host
;
_port
=
port
;
_timeout
=
timeout
;
}
Future
<
PosPrintResult
>
printTicket
(
Ticket
ticket
)
{
if
(
_host
==
null
||
_port
==
null
)
{
return
Future
<
PosPrintResult
>.
value
(
PosPrintResult
.
printerNotSelected
);
}
else
if
(
ticket
==
null
||
ticket
.
bytes
.
isEmpty
)
{
return
Future
<
PosPrintResult
>.
value
(
PosPrintResult
.
ticketEmpty
);
}
return
Socket
.
connect
(
_host
,
_port
,
timeout:
_timeout
)
.
then
((
Socket
socket
)
{
socket
.
add
(
ticket
.
bytes
);
socket
.
destroy
();
return
Future
<
PosPrintResult
>.
value
(
PosPrintResult
.
success
);
}).
catchError
((
dynamic
e
)
{
return
Future
<
PosPrintResult
>.
value
(
PosPrintResult
.
timeout
);
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment