disconnect method

  1. @override
Future<void> disconnect({
  1. int? androidDelay,
  2. bool? queue,
  3. int? timeout,
})
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

@override
Future<void> disconnect(
    {int? androidDelay, bool? queue, int? timeout}) async {
  await Future.delayed(const Duration(seconds: 1));
  _isConnected = false;
  connectionStateController.add(BluetoothConnectionState.disconnected);
}