Closed rdehouss closed 4 years ago
Sorry, false alarm, it was because the code being sync, I was closing destroying the client too soon
The full faulty code
Future _scan(context) async {
BleManager bleManager = BleManager();
await bleManager.createClient();
BluetoothState currentState = await bleManager.bluetoothState();
print(currentState);
if (currentState == BluetoothState.POWERED_OFF) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(
"Bluetooth is off, turn it on to be able to scan for Links",
),
action: SnackBarAction(
label: 'Turn on',
onPressed: () async {
if (Platform.isAndroid) {
try {
await bleManager.enableRadio();
} catch (e) {
print(e);
await AppSettings.openBluetoothSettings();
}
} else {
await AppSettings.openBluetoothSettings();
}
},
),
));
}
bleManager.observeBluetoothState().listen((btState) {
print(btState);
});
return bleManager.destroyClient();
}
The return bleManager.destroyClient();
was the issue :)
Leaving the issue in case someone does the same than me ;)
Good morning!
Thanks a lot already for this library ;)
I just tested the methods
enableRadio
and and despite the fact I see that it's unit tested and so, I understand that it must work somewhere, it throws an exception in my case.I run the application directly on my phone, not an emulator, it fails in both debug and release build.
Best regards,
Raphaël
The version pubspec.lock
The code
=> The error in debug build:
The error in release build:
and
=>
while the following works correctly:
Here is my
flutter doctor -v