Commit aa490654 authored by Andrey's avatar Andrey

Added printing timeout

parent b2d5632d
......@@ -74,11 +74,12 @@ class _MyHomePageState extends State<MyHomePage> {
bluetoothManager.stopScan();
}
Future _sleep(int seconds) {
Future _runDelayed(int seconds) {
return Future<dynamic>.delayed(Duration(seconds: seconds));
}
void _testPrint(BluetoothDevice printer) async {
const int timeout = 5;
if (_isScanning) {
// print('Print failed (scanning in progress)');
showToast('Print failed (scanning in progress)');
......@@ -112,7 +113,7 @@ class _MyHomePageState extends State<MyHomePage> {
showToast('Data sent');
}
// TODO sending disconnect signal should be event-based
_sleep(3).then((dynamic printer) async {
_runDelayed(3).then((dynamic v) async {
print('@@@@DISCONNECTING......');
await bluetoothManager.disconnect();
_isPrinting = false;
......@@ -127,6 +128,13 @@ class _MyHomePageState extends State<MyHomePage> {
break;
}
});
// Printing timeout
_runDelayed(timeout).then((dynamic v) async {
if (_isPrinting) {
_isPrinting = false;
showToast('Print failed');
}
});
}
@override
......
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