pickDevice static method

UCameraDevice? pickDevice(
  1. List<UCameraDevice> devices, {
  2. UCameraFacing facing = UCameraFacing.back,
  3. UCameraLens? lens,
})

Picks the device closest to facing, preferring the given lens.

Implementation

static UCameraDevice? pickDevice(List<UCameraDevice> devices, {UCameraFacing facing = UCameraFacing.back, UCameraLens? lens}) {
  if (devices.isEmpty) return null;
  UCameraDevice? fallback;
  for (final UCameraDevice device in devices) {
    if (device.facing != facing) continue;
    if (lens == null || device.lens == lens) return device;
    fallback ??= device;
  }
  return fallback ?? devices.first;
}