switchCamera method
Switches the active camera to the specified CameraLensDirection (front or rear).
If the camera is not initialized or the selected camera is already active, the function will log an error.
Implementation
Future<void> switchCamera(CameraLensDirection cameraLensDirection) async {
if (_cameraController == null || _onCameraInitialized == null || _onCameraInitializedFailure == null) {
log("failed to switch camera, camera didn't start yet");
return;
}
if (_cameraController?.value.isInitialized != true) {
log("failed to switch camera, camera not yet initialized");
return;
}
if (this.cameraLensDirection == cameraLensDirection) {
log("cameraLensDirection already $cameraLensDirection");
return;
}
if (flashModeState != FlashMode.off) {
await setFlashMode(FlashMode.off);
}
_initializeCameraController(
cameraLensDirection: cameraLensDirection,
resolutionPreset: _resolutionPreset,
imageFormatGroup: _currentImageFormatGroup,
);
}