disconnect method

  1. @override
Future<void> disconnect(
  1. String deviceAddress
)
override

Asynchronously terminates the connection between the host mobile device and a Bluetooth Low Energy (BLE) peripheral.

Disconnecting from a BLE device is an important part of BLE best practices. Proper disconnection ensures that resources like memory and battery are optimized on both the mobile device and the peripheral.

Importance of Disconnecting

  1. Resource Management: Disconnecting releases the system resources occupied by a BLE connection.
  2. Battery Optimization: Disconnecting reduces power consumption on both connected devices.
  3. Security: Maintaining an open connection can expose the devices to potential security risks.
  4. Connection Limits: Disconnecting frees a peripheral connection slot for another device.

Implementation

@override
Future<void> disconnect(String deviceAddress) async {
  await channel.invokeMethod('disconnect', {'address': deviceAddress});
}