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
b2d5632d
Commit
b2d5632d
authored
Jan 15, 2020
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added toaster
parent
a0a71a25
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
6 deletions
+25
-6
main.dart
example/blue/lib/main.dart
+24
-6
pubspec.yaml
example/blue/pubspec.yaml
+1
-0
No files found.
example/blue/lib/main.dart
View file @
b2d5632d
...
...
@@ -2,18 +2,21 @@ import 'dart:async';
import
'dart:convert'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_bluetooth_basic/flutter_bluetooth_basic.dart'
;
import
'package:oktoast/oktoast.dart'
;
void
main
(
)
=>
runApp
(
MyApp
());
class
MyApp
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
title:
'Bluetooth demo'
,
theme:
ThemeData
(
primarySwatch:
Colors
.
blue
,
return
OKToast
(
child:
MaterialApp
(
title:
'Bluetooth demo'
,
theme:
ThemeData
(
primarySwatch:
Colors
.
blue
,
),
home:
MyHomePage
(
title:
'Bluetooth demo'
),
),
home:
MyHomePage
(
title:
'Bluetooth demo'
),
);
}
}
...
...
@@ -31,6 +34,7 @@ class _MyHomePageState extends State<MyHomePage> {
BluetoothManager
bluetoothManager
=
BluetoothManager
.
instance
;
bool
_connected
=
false
;
bool
_isScanning
=
false
;
bool
_isPrinting
=
false
;
List
<
BluetoothDevice
>
_devices
=
[];
StreamSubscription
_scanResultsSubscription
;
StreamSubscription
_isScanningSubscription
;
...
...
@@ -75,6 +79,19 @@ class _MyHomePageState extends State<MyHomePage> {
}
void
_testPrint
(
BluetoothDevice
printer
)
async
{
if
(
_isScanning
)
{
// print('Print failed (scanning in progress)');
showToast
(
'Print failed (scanning in progress)'
);
return
;
}
if
(
_isPrinting
)
{
// print('Print failed (another printing in progress)');
showToast
(
'Print failed (another printing in progress)'
);
return
;
}
_isPrinting
=
true
;
// We have to rescan before connecting, otherwise we can connect only once
await
bluetoothManager
.
startScan
(
timeout:
Duration
(
seconds:
1
));
await
bluetoothManager
.
stopScan
();
...
...
@@ -92,12 +109,13 @@ class _MyHomePageState extends State<MyHomePage> {
print
(
'@@@@SEND DATA......'
);
final
List
<
int
>
bytes
=
latin1
.
encode
(
'test!
\n\n\n
'
).
toList
();
await
bluetoothManager
.
writeData
(
bytes
);
// TODO show message "Data sent"
showToast
(
'Data sent'
);
}
// TODO sending disconnect signal should be event-based
_sleep
(
3
).
then
((
dynamic
printer
)
async
{
print
(
'@@@@DISCONNECTING......'
);
await
bluetoothManager
.
disconnect
();
_isPrinting
=
false
;
});
_connected
=
true
;
break
;
...
...
example/blue/pubspec.yaml
View file @
b2d5632d
...
...
@@ -9,6 +9,7 @@ dependencies:
flutter
:
sdk
:
flutter
cupertino_icons
:
^0.1.2
oktoast
:
^2.3.0
flutter_bluetooth_basic
:
git
:
url
:
git://github.com/andrey-ushakov/flutter_bluetooth_basic
...
...
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