bondState property
Stream<BluetoothBondState>
get
bondState
Get the current bondState of the device (Android Only)
Implementation
Stream<BluetoothBondState> get bondState async* {
// check android
if (Platform.isAndroid == false) {
throw FlutterBluePlusException(ErrorPlatform.fbp, "bondState",
FbpErrorCode.androidOnly.index, "android-only");
}
// get current state if needed
if (FlutterBluePlus._bondStates[remoteId] == null) {
var val = await FlutterBluePlus._methodChannel
.invokeMethod('getBondState', remoteId.str)
.then((args) => BmBondStateResponse.fromMap(args));
// update _bondStates if it is still null after the await
if (FlutterBluePlus._bondStates[remoteId] == null) {
FlutterBluePlus._bondStates[remoteId] = val;
}
}
yield* FlutterBluePlus._methodStream.stream
.where((m) => m.method == "OnBondStateChanged")
.map((m) => m.arguments)
.map((args) => BmBondStateResponse.fromMap(args))
.where((p) => p.remoteId == remoteId)
.map((p) => _bmToBondState(p.bondState))
.newStreamWithInitialValue(
_bmToBondState(FlutterBluePlus._bondStates[remoteId]!.bondState));
}