startScan method
Streams advertisement sightings, optionally filtered to withServices.
Cancelling the subscription (or stopScan) stops the scan.
Implementation
@override
Stream<BleScanResult> startScan({List<Uuid>? withServices}) {
late StreamController<BleScanResult> controller;
controller = StreamController<BleScanResult>.broadcast(
onListen: () {
scanStarted = true;
for (final r in scanResults) {
if (withServices == null ||
withServices.any(r.serviceUuids.contains)) {
controller.add(r);
}
}
if (scanError != null) controller.addError(scanError!);
},
onCancel: () => scanStopped = true,
);
return controller.stream;
}