disconnect method
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
- Resource Management: BLE connections occupy system resources. Failing to disconnect can lead to resource leakage.
- Battery Optimization: BLE connections consume battery power on both connecting and connected devices. Timely disconnection helps in prolonging battery life.
- Security: Maintaining an open connection can expose the devices to potential security risks.
- Connection Limits: BLE peripherals often have a limit on the number of concurrent connections. Disconnecting when done ensures that other devices can connect.
Implementation
@override
Future<void> disconnect(String deviceAddress) async {
await channel.invokeMethod('disconnect', {'address': deviceAddress});
}