switchCamera method
Switch the camera based on the given option.
The option parameter determines how the camera is switched:
- ToggleDirection: Toggles between front and back cameras (default).
- ToggleLensType: Cycles through available lens types on the current camera facing direction.
- SelectCamera: Selects a specific camera direction and/or lens type.
For ToggleDirection, does nothing if the device has less than 2 cameras, or if the current camera direction is CameraFacing.unknown or CameraFacing.external.
For ToggleLensType, does nothing if the device has less than 2 lens types available.
Implementation
Future<void> switchCamera([
SwitchCameraOption option = const ToggleDirection(),
]) async {
_throwIfNotInitialized();
switch (option) {
case ToggleDirection():
await _toggleCameraDirection();
case ToggleLensType():
await _toggleLensType();
case SelectCamera(:final facingDirection, :final lensType):
await _selectCamera(
facingDirection: facingDirection,
lensType: lensType,
);
}
}