scan method

Stream<ZoopDevice> scan (
  1. {ScanMode scanMode: ScanMode.lowLatency,
  2. List<Guid> withServices: const [],
  3. List<Guid> withDevices: const [],
  4. Duration timeout,
  5. bool allowDuplicates: false}
)

Starts a scan for Bluetooth Low Energy devices Timeout closes the stream after a specified Duration

Implementation

Stream<ZoopDevice> scan({
  ScanMode scanMode = ScanMode.lowLatency,
  List<Guid> withServices = const [],
  List<Guid> withDevices = const [],
  Duration timeout,
  bool allowDuplicates = false,
}) async* {
  if (_isScanning.value == true) {
    throw Exception('Another scan is already in progress.');
  }

  // Emit to isScanning
  _isScanning.add(true);

  final killStreams = <Stream>[];
  killStreams.add(_stopScanPill);
  if (timeout != null) {
    killStreams.add(Rx.timer(null, timeout));
  }

  // Clear scan results list
  _scanResults.add(<ZoopDevice>[]);

  try {
    await _channel.invokeMethod('startScan');
  } catch (e) {
    print('Error starting scan.');
    _stopScanPill.add(null);
    _isScanning.add(false);
    throw e;
  }

  FlutterZoop.instance._methodStream
      .where((event) => event.method == "Devices")
      .map((data) {
    print('DATA $data');
  });
}