discovery method

  1. @override
Stream<BluetoothDevice> discovery({
  1. List<ScanFilter>? scanFilters,
})
override

Starts scan for Bluetooth LE devices Note: This is a continuous behavior, don't forget to call stopDiscovery. scanFilters filters the scan results. Throw BTException if failed.

Implementation

@override
Stream<BluetoothDevice> discovery({List<ScanFilter>? scanFilters}) async* {
  try {
    // Clear result
    _scanResults.add([]);
    Map<String, dynamic> args = {};
    args["filters"] = scanFilters == null || scanFilters.isEmpty ? null : scanFilters.map((e) => e.toMap()).toList();
    await methodChannel.invokeMethod("startDiscovery", args);
    yield* _scanResultMethodStream
        .takeUntil(_stopScanPill)
        .doOnDone(stopDiscovery)
        .map((event) => event.arguments)
        .transform(StreamTransformer(_addDeviceTransform));
  } on BTException catch (_) {
    rethrow;
  } on PlatformException catch (e) {
    throw BTException.fromPlatform(e);
  }
}