connect method
Establishes a connection to the Bluetooth Device.
timeout
if timeout occurs, cancel the connection request and throw exception
mtu
Android only. Request a larger mtu right after connection, if set.
autoConnect
reconnect whenever the device is found
- if true, this function always returns immediately.
- you must listen to connectionState
to know when connection occurs.
- auto connect is turned off by calling disconnect
- auto connect results in a slower connection process compared to a direct connection
because it relies on the internal scheduling of background scans.
Implementation
@override
Future<void> connect({bool? autoConnect, int? mtu, Duration? timeout}) async {
connectionStateController.add(BluetoothConnectionState.disconnected);
await Future.delayed(const Duration(seconds: 1));
_isConnected = true;
connectionStateController.add(BluetoothConnectionState.connected);
}