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
57840358
Commit
57840358
authored
Jan 15, 2020
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed double printing bug. Print custom text.
parent
998d07f8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
12 deletions
+7
-12
main.dart
example/blue/lib/main.dart
+1
-1
printer_bluetooth_manager.dart
lib/src/printer_bluetooth_manager.dart
+6
-11
No files found.
example/blue/lib/main.dart
View file @
57840358
...
...
@@ -59,7 +59,7 @@ class _MyHomePageState extends State<MyHomePage> {
void
_testPrint
(
PrinterBluetooth
printer
)
async
{
printerManager
.
selectPrinter
(
printer
);
printerManager
.
printLine
(
'
hello
'
).
then
((
val
)
{
printerManager
.
printLine
(
'
====== @@@ hello
\n\n\n
'
).
then
((
val
)
{
showToast
(
'Success!'
);
}).
catchError
((
dynamic
e
)
{
print
(
'catched:
${e.toString()}
'
);
...
...
lib/src/printer_bluetooth_manager.dart
View file @
57840358
...
...
@@ -34,20 +34,17 @@ class PrinterBluetooth {
/// Printer Bluetooth Manager
class
PrinterBluetoothManager
{
// PrinterBluetoothManager() {
// }
final
BluetoothManager
_bluetoothManager
=
BluetoothManager
.
instance
;
bool
_isScanning
=
false
;
bool
_isPrinting
=
false
;
bool
_isConnected
=
false
;
StreamSubscription
_scanResultsSubscription
;
StreamSubscription
_isScanningSubscription
;
PrinterBluetooth
_selectedPrinter
;
Stream
<
bool
>
get
isScanningStream
=>
_bluetoothManager
.
isScanning
;
BehaviorSubject
<
List
<
PrinterBluetooth
>>
_scanResults
=
final
BehaviorSubject
<
List
<
PrinterBluetooth
>>
_scanResults
=
BehaviorSubject
.
seeded
([]);
Stream
<
List
<
PrinterBluetooth
>>
get
scanResults
=>
_scanResults
.
stream
;
...
...
@@ -61,11 +58,9 @@ class PrinterBluetoothManager {
_bluetoothManager
.
startScan
(
timeout:
Duration
(
seconds:
4
));
_scanResultsSubscription
=
_bluetoothManager
.
scanResults
.
listen
((
devices
)
{
// print('====scan result');
_scanResults
.
add
(
devices
.
map
((
d
)
=>
PrinterBluetooth
(
d
)).
toList
());
});
// TODO move listener to constructor
_isScanningSubscription
=
_bluetoothManager
.
isScanning
.
listen
((
isScanningCurrent
)
async
{
// If isScanning value changed (scan just stopped)
...
...
@@ -87,7 +82,6 @@ class PrinterBluetoothManager {
Future
<
void
>
printLine
(
String
text
)
async
{
const
int
timeout
=
5
;
print
(
'============
$_isScanning
'
);
if
(
_selectedPrinter
==
null
)
{
throw
Exception
(
'Print failed (Select a printer first)'
);
}
...
...
@@ -113,9 +107,8 @@ class PrinterBluetoothManager {
case
BluetoothManager
.
CONNECTED
:
print
(
'********************* CONNECTED'
);
// To avoid double call
if
(
_selectedPrinter
.
_device
.
connected
==
null
||
!
_selectedPrinter
.
_device
.
connected
)
{
final
List
<
int
>
bytes
=
latin1
.
encode
(
'test!
\n\n\n
'
).
toList
();
if
(!
_isConnected
)
{
final
List
<
int
>
bytes
=
latin1
.
encode
(
text
).
toList
();
await
_bluetoothManager
.
writeData
(
bytes
);
// TODO Notify data sent
}
...
...
@@ -125,9 +118,11 @@ class PrinterBluetoothManager {
await
_bluetoothManager
.
disconnect
();
_isPrinting
=
false
;
});
_isConnected
=
true
;
break
;
case
BluetoothManager
.
DISCONNECTED
:
print
(
'********************* DISCONNECTED'
);
_isConnected
=
false
;
break
;
default
:
break
;
...
...
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