getDevices method Null safety

Future<Set<AudioDevice>> getDevices(
  1. {bool includeInputs = true,
  2. bool includeOutputs = true}
)

Completes with a list of available audio devices.

Implementation

Future<Set<AudioDevice>> getDevices(
    {bool includeInputs = true, bool includeOutputs = true}) async {
  final devices = <AudioDevice>{};
  if (_androidAudioManager != null) {
    var flags = AndroidGetAudioDevicesFlags.none;
    if (includeInputs) flags |= AndroidGetAudioDevicesFlags.inputs;
    if (includeOutputs) flags |= AndroidGetAudioDevicesFlags.outputs;
    final androidDevices = await _androidAudioManager!.getDevices(flags);
    devices.addAll(androidDevices.map(_androidDevice2device).toSet());
  } else if (_avAudioSession != null) {
    final currentRoute = await _avAudioSession!.currentRoute;
    if (includeInputs) {
      final darwinInputs = await _avAudioSession!.availableInputs;
      devices.addAll(darwinInputs
          .map((port) => _darwinPort2device(port, inputPorts: darwinInputs))
          .toSet());
      devices.addAll(currentRoute.inputs.map((port) => _darwinPort2device(
            port,
            inputPorts: currentRoute.inputs,
            outputPorts: currentRoute.outputs,
          )));
    }
    if (includeOutputs) {
      devices.addAll(currentRoute.outputs.map((port) => _darwinPort2device(
            port,
            inputPorts: currentRoute.inputs,
            outputPorts: currentRoute.outputs,
          )));
    }
  }
  return devices;
}