woodemi / quick.flutter

54 stars 64 forks source link

Make startScan() async and check BLE availability #9

Closed azimuthdeveloper closed 2 years ago

azimuthdeveloper commented 2 years ago

On Windows, if startScan() is called while the Bluetooth switch is in the "off" state, quick_blue causes a native crash.

This PR first checks that Bluetooth is enabled, and if it is not, returns an error back up to the Flutter system to deal with.

It also changes the implementation of startScan to async. That's because, in my tests, it seems like the error was only caught properly if startScan was made async.

EDIT: Also check if the bluetooth adapter is available before trying to use it. It's possible that the bluetooth object could be null if there was no eligible hardware to be used on the computer.

Sunbreak commented 2 years ago

There is isBluetoothAvailable. Why check the bluetoothRadio again in startScan?

azimuthdeveloper commented 2 years ago

Because if there isn't an available BLE adapter or its turned off on the system, it causes a native crash, which makes the entire app crash. I'm trying to prevent against native crashes for any reason.

Sunbreak commented 2 years ago

Fix async & format