switchCamera method
Flips between the first back and front cameras.
Implementation
Future<void> switchCamera() async {
final List<UCameraDevice> devices = await availableCameras();
if (devices.length < 2) return;
final UCameraFacing target = value.device?.isFront == true ? UCameraFacing.back : UCameraFacing.front;
UCameraDevice? next;
for (final UCameraDevice device in devices) {
if (device.facing == target) {
next = device;
break;
}
}
if (next == null) return;
if (value.isRecording) await stopVideoRecording();
_config = _config.copyWith(deviceId: next.id, facing: target);
await suspend();
await initialize();
}