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
c04f2da4
Commit
c04f2da4
authored
Jan 15, 2020
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using Ticket class. Print test ticket (bluetooth).
parent
6d0a5c12
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
601 additions
and
76 deletions
+601
-76
logo.png
example/blue/assets/logo.png
+0
-0
main.dart
example/blue/lib/main.dart
+64
-10
pubspec.yaml
example/blue/pubspec.yaml
+3
-0
esc_pos_printer.dart
lib/esc_pos_printer.dart
+1
-1
enums.dart
lib/src/enums.dart
+9
-0
pos_generator.dart
lib/src/pos_generator.dart
+0
-43
printer_bluetooth_manager.dart
lib/src/printer_bluetooth_manager.dart
+7
-22
ticket.dart
lib/src/ticket.dart
+517
-0
No files found.
example/blue/assets/logo.png
0 → 100644
View file @
c04f2da4
2.33 KB
example/blue/lib/main.dart
View file @
c04f2da4
import
'dart:typed_data'
;
import
'package:flutter/services.dart'
;
import
'package:image/image.dart'
;
import
'package:esc_pos_printer/esc_pos_printer.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
hide
Image
;
import
'package:oktoast/oktoast.dart'
;
void
main
(
)
=>
runApp
(
MyApp
());
...
...
@@ -57,19 +60,70 @@ class _MyHomePageState extends State<MyHomePage> {
void
_testPrint
(
PrinterBluetooth
printer
)
async
{
printerManager
.
selectPrinter
(
printer
);
// printerManager.addText('left', styles: PosStyles(align: PosTextAlign.left));
// printerManager.addText('center',
// styles: PosStyles(align: PosTextAlign.center));
// printerManager.addText('right',
// styles: PosStyles(align: PosTextAlign.right), linesAfter: 3);
Ticket
ticket
=
Ticket
(
PaperSize
.
mm58
);
printerManager
.
addT
ext
(
ticket
.
t
ext
(
'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'
);
printerManager
.
addT
ext
(
'Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ'
,
ticket
.
t
ext
(
'Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ'
,
styles:
PosStyles
(
codeTable:
PosCodeTable
.
westEur
));
printerManager
.
addEmptyLines
(
3
);
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
);
ticket
.
text
(
'Align left'
,
styles:
PosStyles
(
align:
PosTextAlign
.
left
));
ticket
.
text
(
'Align center'
,
styles:
PosStyles
(
align:
PosTextAlign
.
center
));
ticket
.
text
(
'Align right'
,
styles:
PosStyles
(
align:
PosTextAlign
.
right
),
linesAfter:
1
);
ticket
.
row
([
PosColumn
(
text:
'col3'
,
width:
3
,
styles:
PosStyles
(
align:
PosTextAlign
.
center
,
underline:
true
),
),
PosColumn
(
text:
'col6'
,
width:
6
,
styles:
PosStyles
(
align:
PosTextAlign
.
center
,
underline:
true
),
),
PosColumn
(
text:
'col3'
,
width:
3
,
styles:
PosStyles
(
align:
PosTextAlign
.
center
,
underline:
true
),
),
]);
ticket
.
text
(
'Text size 200%'
,
styles:
PosStyles
(
height:
PosTextSize
.
size2
,
width:
PosTextSize
.
size2
,
));
// Print image
final
ByteData
data
=
await
rootBundle
.
load
(
'assets/logo.png'
);
final
Uint8List
bytes
=
data
.
buffer
.
asUint8List
();
final
Image
image
=
decodeImage
(
bytes
);
ticket
.
image
(
image
);
// Print image using an alternative (obsolette) command
// ticket.imageRaster(image);
// Print barcode
final
List
<
int
>
barData
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
0
,
4
];
ticket
.
barcode
(
Barcode
.
upcA
(
barData
));
// Print mixed (chinese + latin) text. Only for printers supporting Kanji mode
// ticket.text(
// 'hello ! 中文字 # world @ éphémère &',
// styles: PosStyles(codeTable: PosCodeTable.westEur),
// containsChinese: true,
// );
ticket
.
feed
(
2
);
printerManager
.
printTicket
().
then
((
val
)
{
printerManager
.
printTicket
(
ticket
).
then
((
val
)
{
showToast
(
'Success!'
);
}).
catchError
((
dynamic
e
)
{
print
(
'catched:
${e.toString()}
'
);
...
...
example/blue/pubspec.yaml
View file @
c04f2da4
...
...
@@ -10,6 +10,7 @@ dependencies:
sdk
:
flutter
cupertino_icons
:
^0.1.2
oktoast
:
^2.3.0
image
:
^2.1.4
esc_pos_printer
:
path
:
../../
...
...
@@ -19,3 +20,5 @@ dev_dependencies:
flutter
:
uses-material-design
:
true
assets
:
-
assets/logo.png
lib/esc_pos_printer.dart
View file @
c04f2da4
...
...
@@ -9,7 +9,7 @@ library esc_pos_printer;
export
'./src/barcode.dart'
;
export
'./src/enums.dart'
;
export
'./src/pos_column.dart'
;
export
'./src/pos_generator.dart'
;
export
'./src/pos_styles.dart'
;
export
'./src/printer.dart'
;
export
'./src/printer_bluetooth_manager.dart'
;
export
'./src/ticket.dart'
;
lib/src/enums.dart
View file @
c04f2da4
...
...
@@ -26,6 +26,15 @@ class PosTextSize {
16
*
(
width
.
value
-
1
)
+
(
height
.
value
-
1
);
}
class
PaperSize
{
const
PaperSize
.
_internal
(
this
.
value
);
final
int
value
;
static
const
mm58
=
PaperSize
.
_internal
(
1
);
static
const
mm80
=
PaperSize
.
_internal
(
2
);
static
int
width
(
PaperSize
size
)
=>
size
==
PaperSize
.
mm58
?
350
:
512
;
}
class
PosBeepDuration
{
const
PosBeepDuration
.
_internal
(
this
.
value
);
final
int
value
;
...
...
lib/src/pos_generator.dart
deleted
100644 → 0
View file @
6d0a5c12
import
'dart:convert'
;
// import 'dart:io';
import
'dart:typed_data'
;
// import 'package:gbk_codec/gbk_codec.dart';
// import 'package:hex/hex.dart';
// import 'package:image/image.dart';
// import 'barcode.dart';
import
'commands.dart'
;
import
'enums.dart'
;
// import 'pos_column.dart';
import
'pos_styles.dart'
;
class
PosGenerator
{
static
List
<
int
>
emptyLines
(
int
n
)
{
if
(
n
>
0
)
{
return
latin1
.
encode
(
List
.
filled
(
n
,
'
\n
'
).
join
());
}
return
[];
}
static
List
<
int
>
text
(
String
text
,
{
PosStyles
styles
=
const
PosStyles
(),
int
linesAfter
=
0
,
})
{
List
<
int
>
bytes
=
[];
bytes
+=
latin1
.
encode
(
styles
.
align
==
PosTextAlign
.
left
?
cAlignLeft
:
(
styles
.
align
==
PosTextAlign
.
center
?
cAlignCenter
:
cAlignRight
));
// Set local code table
if
(
styles
.
codeTable
!=
null
)
{
bytes
+=
Uint8List
.
fromList
(
List
.
from
(
cCodeTable
.
codeUnits
)..
add
(
styles
.
codeTable
.
value
),
);
}
bytes
+=
latin1
.
encode
(
text
+
'
\n
'
);
bytes
+=
emptyLines
(
linesAfter
);
return
bytes
;
}
}
lib/src/printer_bluetooth_manager.dart
View file @
c04f2da4
...
...
@@ -41,7 +41,6 @@ class PrinterBluetoothManager {
StreamSubscription
_scanResultsSubscription
;
StreamSubscription
_isScanningSubscription
;
PrinterBluetooth
_selectedPrinter
;
List
<
int
>
_printBuffer
=
[];
final
BehaviorSubject
<
bool
>
_isScanning
=
BehaviorSubject
.
seeded
(
false
);
Stream
<
bool
>
get
isScanningStream
=>
_isScanning
.
stream
;
...
...
@@ -107,7 +106,7 @@ class PrinterBluetoothManager {
_bluetoothManager
.
state
.
listen
((
state
)
async
{
switch
(
state
)
{
case
BluetoothManager
.
CONNECTED
:
print
(
'********************* CONNECTED'
);
//
print('********************* CONNECTED');
// To avoid double call
if
(!
_isConnected
)
{
await
_bluetoothManager
.
writeData
(
bytes
);
...
...
@@ -115,14 +114,14 @@ class PrinterBluetoothManager {
}
// TODO sending disconnect signal should be event-based
_runDelayed
(
3
).
then
((
dynamic
v
)
async
{
print
(
'DISCONNECTING......'
);
//
print('DISCONNECTING......');
await
_bluetoothManager
.
disconnect
();
_isPrinting
=
false
;
});
_isConnected
=
true
;
break
;
case
BluetoothManager
.
DISCONNECTED
:
print
(
'********************* DISCONNECTED'
);
//
print('********************* DISCONNECTED');
_isConnected
=
false
;
break
;
default
:
...
...
@@ -139,26 +138,12 @@ class PrinterBluetoothManager {
});
}
void
addText
(
String
text
,
{
PosStyles
styles
=
const
PosStyles
(),
int
linesAfter
=
0
,
})
{
_printBuffer
+=
PosGenerator
.
text
(
text
,
styles:
styles
,
linesAfter:
linesAfter
);
}
void
addEmptyLines
(
int
n
)
{
_printBuffer
+=
PosGenerator
.
emptyLines
(
n
);
}
Future
<
void
>
printTicket
()
async
{
if
(
_printBuffer
.
isNotEmpty
)
{
final
Future
<
void
>
res
=
writeBytes
(
_printBuffer
);
_printBuffer
=
[];
Future
<
void
>
printTicket
(
Ticket
ticket
)
async
{
if
(
ticket
.
bytes
.
isNotEmpty
)
{
final
Future
<
void
>
res
=
writeBytes
(
ticket
.
bytes
);
return
res
;
}
else
{
throw
Exception
(
'Print failed (
print buffer
is empty)'
);
throw
Exception
(
'Print failed (
ticket
is empty)'
);
}
}
}
lib/src/ticket.dart
0 → 100644
View file @
c04f2da4
This diff is collapsed.
Click to expand it.
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