connect method
Implementation
@override
Future<bool> connect(
String deviceId,
int timeout,
void Function(String address)? onDisconnect,
) async {
if (onDisconnect != null) {
_connectStreams[deviceId] =
_connectEventChannel.receiveBroadcastStream().listen((result) {
if (result["value"] == null) {
throw PlatformException(code: "connect(): error retrieving value");
}
final addr = result["value"] as String;
_connectStreams[addr]?.cancel();
_connectStreams.remove(addr);
onDisconnect.call(addr);
});
}
final result = await _methodChannel.invokeMethod<bool?>('connect', {
'deviceId': deviceId,
'timeout': timeout,
});
if (result == null) {
throw PlatformException(code: "connect(): error retrieving value");
}
return result;
}