scanDevices method

  1. @override
Stream<BluetoothDevice> scanDevices(
  1. String? name,
  2. List<String> withServices,
  3. ManufacturerSpecificData? manufacturerSpecificData
)
override

Implementation

@override
Stream<BluetoothDevice> scanDevices(String? name, List<String> withServices,
    ManufacturerSpecificData? manufacturerSpecificData) async* {
  const events = EventChannel("scan_blep");

  var arguments = {'name': name, 'withServices': withServices};

  if (manufacturerSpecificData != null) {
    arguments.addAll({
      'manufacturerId': manufacturerSpecificData.id,
      'manufacturerData': manufacturerSpecificData.data,
    });
  }

  await methodChannel.invokeMethod('scanDevices', arguments);

  yield* events.receiveBroadcastStream().map((deviceData) =>
      BluetoothDevice(name: deviceData['name'], id: deviceData['id'], manufacturerId: deviceData['manufacturerId']));
}