updatePreset method

  1. @override
Future<void> updatePreset(
  1. CameraControllerPreset preset
)
override

Called when a CameraController has changed CameraControllerPresets.

Implementation

@override
Future<void> updatePreset(CameraControllerPreset preset) async {
  verifyAttached();
  final List<CameraSize>? supportedSizes =
      await _controller.cameraParameters.getSupportedVideoSizes();

  if (supportedSizes != null) {
    _sortCameraSizes(supportedSizes);
    switch (preset) {
      case CameraControllerPreset.low:
        specifiedSize = supportedSizes.first;
        mediaRecorder.setVideoSize(
          supportedSizes.first.width,
          supportedSizes.first.height,
        );
        break;
      case CameraControllerPreset.medium:
        final int midIndex = ((supportedSizes.length - 1) / 2).round();
        specifiedSize = supportedSizes[midIndex];
        mediaRecorder.setVideoSize(
          supportedSizes[midIndex].width,
          supportedSizes[midIndex].height,
        );
        break;
      case CameraControllerPreset.high:
        specifiedSize = supportedSizes.last;
        mediaRecorder.setVideoSize(
          supportedSizes.last.width,
          supportedSizes.last.height,
        );
        break;
    }
    return;
  }

  final List<CameraSize> previewSizes =
      await _controller.cameraParameters.getSupportedPreviewSizes();
  _sortCameraSizes(previewSizes);
  switch (preset) {
    case CameraControllerPreset.low:
      specifiedSize = previewSizes.first;
      _controller.cameraParameters.setPreviewSize(
        previewSizes.first.width,
        previewSizes.first.height,
      );
      break;
    case CameraControllerPreset.medium:
      final int midIndex = ((previewSizes.length - 1) / 2).round();
      specifiedSize = previewSizes[midIndex];
      _controller.cameraParameters.setPreviewSize(
        previewSizes[midIndex].width,
        previewSizes[midIndex].height,
      );
      break;
    case CameraControllerPreset.high:
      specifiedSize = previewSizes.last;
      _controller.cameraParameters.setPreviewSize(
        previewSizes.last.width,
        previewSizes.last.height,
      );
      break;
  }

  return _controller.camera.setParameters(_controller.cameraParameters);
}