Commit 4d83fd23 authored by Andrey's avatar Andrey

_isScanning stream fixed.

parent 57840358
...@@ -35,14 +35,14 @@ class PrinterBluetooth { ...@@ -35,14 +35,14 @@ class PrinterBluetooth {
/// Printer Bluetooth Manager /// Printer Bluetooth Manager
class PrinterBluetoothManager { class PrinterBluetoothManager {
final BluetoothManager _bluetoothManager = BluetoothManager.instance; final BluetoothManager _bluetoothManager = BluetoothManager.instance;
bool _isScanning = false;
bool _isPrinting = false; bool _isPrinting = false;
bool _isConnected = false; bool _isConnected = false;
StreamSubscription _scanResultsSubscription; StreamSubscription _scanResultsSubscription;
StreamSubscription _isScanningSubscription; StreamSubscription _isScanningSubscription;
PrinterBluetooth _selectedPrinter; PrinterBluetooth _selectedPrinter;
Stream<bool> get isScanningStream => _bluetoothManager.isScanning; final BehaviorSubject<bool> _isScanning = BehaviorSubject.seeded(false);
Stream<bool> get isScanningStream => _isScanning.stream;
final BehaviorSubject<List<PrinterBluetooth>> _scanResults = final BehaviorSubject<List<PrinterBluetooth>> _scanResults =
BehaviorSubject.seeded([]); BehaviorSubject.seeded([]);
...@@ -64,11 +64,11 @@ class PrinterBluetoothManager { ...@@ -64,11 +64,11 @@ class PrinterBluetoothManager {
_isScanningSubscription = _isScanningSubscription =
_bluetoothManager.isScanning.listen((isScanningCurrent) async { _bluetoothManager.isScanning.listen((isScanningCurrent) async {
// If isScanning value changed (scan just stopped) // If isScanning value changed (scan just stopped)
if (_isScanning && !isScanningCurrent) { if (_isScanning.value && !isScanningCurrent) {
_scanResultsSubscription.cancel(); _scanResultsSubscription.cancel();
_isScanningSubscription.cancel(); _isScanningSubscription.cancel();
} }
_isScanning = isScanningCurrent; _isScanning.add(isScanningCurrent);
}); });
} }
...@@ -85,7 +85,7 @@ class PrinterBluetoothManager { ...@@ -85,7 +85,7 @@ class PrinterBluetoothManager {
if (_selectedPrinter == null) { if (_selectedPrinter == null) {
throw Exception('Print failed (Select a printer first)'); throw Exception('Print failed (Select a printer first)');
} }
if (_isScanning) { if (_isScanning.value) {
throw Exception('Print failed (scanning in progress)'); throw Exception('Print failed (scanning in progress)');
} }
if (_isPrinting) { if (_isPrinting) {
......
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