If I start the scan with BT disabled then obviously no devices will be found, but the issues is that an Unhandled Exception will be thrown, which isn't graceful:
BluetoothManager bluetoothManager = BluetoothManager.instance;
//...
bluetoothManager.startScan(timeout: Duration(seconds: 2));
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(startScan, getBluetoothLeScanner() is null. Is the Adapter on?, null)
#0 BluetoothManager.scan (package:flutter_bluetooth_basic/src/bluetooth_manager.dart:85:7)
<asynchronous suspension>
#1 BluetoothManager.startScan (package:flutter_bluetooth_basic/src/bluetooth_manager.dart:116:11)...
I can work around that by catching it, like so:
bluetoothManager.startScan(timeout: Duration(seconds: 2)).catchError((e){
// tell the user to check if BT is on.
// print(e);
});
But that isn't graceful either IMHO, also I don't know if the devices is missing BT (like an emulator) or it is just turned off.
I noticed that in "FlutterBluetoothBasicPlugin.java" these cases are already covered:
case "isAvailable":
result.success(mBluetoothAdapter != null);
break;
case "isOn":
result.success(mBluetoothAdapter.isEnabled());
break;
So it would be nice if we could call them from Flutter with bluetoothManager.isAvailable() and bluetoothManager.isOn().
If I start the scan with BT disabled then obviously no devices will be found, but the issues is that an Unhandled Exception will be thrown, which isn't graceful:
I can work around that by catching it, like so:
But that isn't graceful either IMHO, also I don't know if the devices is missing BT (like an emulator) or it is just turned off.
I noticed that in "FlutterBluetoothBasicPlugin.java" these cases are already covered:
So it would be nice if we could call them from Flutter with bluetoothManager.isAvailable() and bluetoothManager.isOn().