Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing isAvailable and isOn to Flutter. #10

Open
Uros-V opened this issue Apr 16, 2020 · 0 comments
Open

Exposing isAvailable and isOn to Flutter. #10

Uros-V opened this issue Apr 16, 2020 · 0 comments

Comments

@Uros-V
Copy link

Uros-V commented Apr 16, 2020

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant