Commit aa490654 authored by Andrey's avatar Andrey

Added printing timeout

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