connect method

  1. @override
Future<Stream<BleConnectionState>> connect({
  1. required String deviceAddress,
})
override

Initiates a connection to a BLE peripheral and returns a Stream representing the connection state.

Implementation

@override
Future<Stream<BleConnectionState>> connect({required String deviceAddress}) async {
  final StreamController<BleConnectionState> controller = StreamController<BleConnectionState>.broadcast();
  _connectionControllers[deviceAddress] = controller;

  // Add the initial connection state, or default to disconnected if not set.
  final BleConnectionState initialState = _connectionStates[deviceAddress] ?? BleConnectionState.disconnected;
  controller.add(initialState);

  return controller.stream;
}