searchBleDevices method

  1. @override
Stream<ESPDevice> searchBleDevices(
  1. String prefix
)
override

Start searching for BLE devices with the given prefix Returns a stream of discovered devices

Implementation

@override
Stream<ESPDevice> searchBleDevices(String prefix) {
  _bleDeviceController?.close();
  _bleDeviceController = StreamController<ESPDevice>.broadcast();

  methodChannel.invokeMethod('searchBleDevices', {'prefix': prefix});

  _bleDeviceSubscription = bleDeviceEventChannel
      .receiveBroadcastStream()
      .listen(
        (event) {
          if (event is Map) {
            final device = ESPDevice.fromMap(
              Map<String, dynamic>.from(event),
            );
            _bleDeviceController?.add(device);
          }
        },
        onError: (error) {
          _bleDeviceController?.addError(error);
        },
      );

  return _bleDeviceController!.stream;
}