bondState property

Stream<BluetoothBondState> get bondState

Get the current bondState of the device (Android Only)

Implementation

Stream<BluetoothBondState> get bondState async* {
  // check android
  if (kIsWeb || !Platform.isAndroid) {
    throw FlutterBluePlusException(ErrorPlatform.fbp, "bondState",
        FbpErrorCode.androidOnly.index, "android-only");
  }

  // get current state if needed
  if (FlutterBluePlus._bondStates[remoteId] == null) {
    var val = await FlutterBluePlus._invokeMethod(() =>
        FlutterBluePlusPlatform.instance
            .getBondState(BmBondStateRequest(remoteId: remoteId)));
    // update _bondStates if it is still null after the await
    if (FlutterBluePlus._bondStates[remoteId] == null) {
      FlutterBluePlus._bondStates[remoteId] = val;
    }
  }

  yield* FlutterBluePlusPlatform.instance.onBondStateChanged
      .where((p) => p.remoteId == remoteId)
      .map((p) => _bmToBondState(p.bondState))
      .newStreamWithInitialValue(
          _bmToBondState(FlutterBluePlus._bondStates[remoteId]!.bondState));
}