disconnect method

Future<void> disconnect({
  1. int androidDelay = 2000,
  2. int timeout = 35,
  3. bool queue = true,
})
override

Cancels connection to the Bluetooth Device

  • queue If true, this disconnect request will be executed after all other operations complete. If false, this disconnect request will be executed right now, i.e. skipping to the front of the fbp operation queue, which is useful to cancel an in-progress connection attempt.
  • androidDelay Android only. Minimum gap in milliseconds between connect and disconnect to workaround a race condition that leaves connection stranded. A stranded connection in this case refers to a connection that FBP and Android Bluetooth stack are not aware of and thus cannot be disconnected because there is no gatt handle. https://issuetracker.google.com/issues/37121040 From testing, 2 second delay appears to be enough.

Implementation

Future<void> disconnect({
  int androidDelay = 2000, // TODO: implementation missing
  int timeout = 35, // TODO: implementation missing
  bool queue = true, // TODO: implementation missing
}) async {
  try {
    // TODO: bug in WinBle; devices once paired are never connected unless the bonding is removed
    // await WinBle.unPair(_address);
    await WinBle.disconnect(_address);
  } catch (e) {
    log(e.toString());
  } finally {
    FlutterBluePlusWindows._deviceSet.remove(this);

    FlutterBluePlusWindows._lastChrs[remoteId]?.clear();
    FlutterBluePlusWindows._isNotifying[remoteId]?.clear();
  }
}