config.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // Copyright 2019 The FlutterCandies author. All rights reserved.
  2. // Use of this source code is governed by an Apache license that can be found
  3. // in the LICENSE file.
  4. import 'package:camera/camera.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter/services.dart';
  7. import 'package:photo_manager/photo_manager.dart';
  8. import '../delegates/camera_picker_text_delegate.dart';
  9. import 'type_defs.dart';
  10. /// {@template wechat_camera_picker.CameraPickerConfig}
  11. /// Configurations for the [CameraPicker].
  12. /// [CameraPicker] 的配置项
  13. /// {@endtemplate}
  14. final class CameraPickerConfig {
  15. const CameraPickerConfig({
  16. this.enableRecording = false,
  17. this.onlyEnableRecording = false,
  18. this.enableTapRecording = false,
  19. this.enableAudio = true,
  20. this.enableSetExposure = true,
  21. this.enableExposureControlOnPoint = true,
  22. this.enablePinchToZoom = true,
  23. this.enablePullToZoomInRecord = true,
  24. this.enableScaledPreview = false,
  25. this.shouldDeletePreviewFile = false,
  26. this.shouldAutoPreviewVideo = true,
  27. this.maximumRecordingDuration = const Duration(seconds: 15),
  28. this.minimumRecordingDuration = const Duration(seconds: 1),
  29. this.theme,
  30. this.textDelegate,
  31. this.cameraQuarterTurns = 0,
  32. this.resolutionPreset = ResolutionPreset.ultraHigh,
  33. this.imageFormatGroup = ImageFormatGroup.unknown,
  34. this.preferredLensDirection = CameraLensDirection.back,
  35. this.preferredFlashMode = FlashMode.off,
  36. this.lockCaptureOrientation,
  37. this.foregroundBuilder,
  38. this.previewTransformBuilder,
  39. this.onEntitySaving,
  40. this.onError,
  41. this.onXFileCaptured,
  42. this.onMinimumRecordDurationNotMet,
  43. this.onPickConfirmed,
  44. this.permissionRequestOption,
  45. }) : assert(
  46. enableRecording == true || onlyEnableRecording != true,
  47. 'Recording mode error.',
  48. );
  49. /// Whether the picker can record video.
  50. /// 选择器是否可以录像
  51. final bool enableRecording;
  52. /// Whether the picker can record video only.
  53. /// 选择器是否只可以录像
  54. final bool onlyEnableRecording;
  55. /// Whether allow the record can start with single tap.
  56. /// 选择器是否可以单击录像
  57. ///
  58. /// It only works when [onlyEnableRecording] is true.
  59. /// 仅在 [onlyEnableRecording] 为 true 时生效。
  60. final bool enableTapRecording;
  61. /// Whether the picker should record audio.
  62. /// 选择器录像时是否需要录制声音
  63. final bool enableAudio;
  64. /// Whether users can set the exposure point by tapping.
  65. /// 用户是否可以在界面上通过点击设定曝光点
  66. final bool enableSetExposure;
  67. /// Whether users can adjust exposure according to the set point.
  68. /// 用户是否可以根据已经设置的曝光点调节曝光度
  69. final bool enableExposureControlOnPoint;
  70. /// Whether users can zoom the camera by pinch.
  71. /// 用户是否可以在界面上双指缩放相机对焦
  72. final bool enablePinchToZoom;
  73. /// Whether users can zoom by pulling up when recording video.
  74. /// 用户是否可以在录制视频时上拉缩放
  75. final bool enablePullToZoomInRecord;
  76. /// Whether the camera preview should be scaled during captures.
  77. /// 拍摄过程中相机预览是否需要缩放
  78. final bool enableScaledPreview;
  79. /// {@template wechat_camera_picker.shouldDeletePreviewFile}
  80. /// Whether the preview file will be delete when pop.
  81. /// 返回页面时是否删除预览文件
  82. /// {@endtemplate}
  83. final bool shouldDeletePreviewFile;
  84. /// {@template wechat_camera_picker.shouldAutoPreviewVideo}
  85. /// Whether the video should be played instantly in the preview.
  86. /// 在预览时是否直接播放视频
  87. /// {@endtemplate}
  88. final bool shouldAutoPreviewVideo;
  89. /// The maximum duration of the video recording process.
  90. /// 录制视频最长时长
  91. ///
  92. /// Defaults to 15 seconds, allow `null` for unrestricted video recording.
  93. /// 默认为 15 秒,可以使用 `null` 来设置无限制的视频录制
  94. final Duration? maximumRecordingDuration;
  95. /// The minimum duration of the video recording process.
  96. /// 录制视频最短时长。
  97. ///
  98. /// Defaults to and cannot be lower than 1 second.
  99. /// 默认且不能少于 1 秒。
  100. final Duration minimumRecordingDuration;
  101. /// Theme data for the picker.
  102. /// 选择器的主题
  103. final ThemeData? theme;
  104. /// The number of clockwise quarter turns the camera view should be rotated.
  105. /// 摄像机视图顺时针旋转次数,每次90度
  106. final int cameraQuarterTurns;
  107. /// Text delegate that controls text in widgets.
  108. /// 控制部件中的文字实现
  109. final CameraPickerTextDelegate? textDelegate;
  110. /// Present resolution for the camera.
  111. /// 相机的分辨率预设
  112. final ResolutionPreset resolutionPreset;
  113. /// The [ImageFormatGroup] describes the output of the raw image format.
  114. /// 输出图像的格式描述
  115. final ImageFormatGroup imageFormatGroup;
  116. /// Which lens direction is preferred when first using the camera,
  117. /// typically with the front or the back direction.
  118. /// 首次使用相机时首选的镜头方向,通常是前置或后置。
  119. final CameraLensDirection preferredLensDirection;
  120. /// {@macro wechat_camera_picker.ForegroundBuilder}
  121. final ForegroundBuilder? foregroundBuilder;
  122. /// {@macro wechat_camera_picker.PreviewTransformBuilder}
  123. final PreviewTransformBuilder? previewTransformBuilder;
  124. /// Whether the camera should be locked to the specific orientation
  125. /// during captures.
  126. /// 摄像机在拍摄时锁定的旋转角度
  127. final DeviceOrientation? lockCaptureOrientation;
  128. /// Which flash mode is preferred when first using the camera,
  129. /// typically with the auto mode.
  130. /// 首次使用相机时首选的闪光灯,通常是自动模式。
  131. final FlashMode preferredFlashMode;
  132. /// {@macro wechat_camera_picker.EntitySaveCallback}
  133. final EntitySaveCallback? onEntitySaving;
  134. /// {@macro wechat_camera_picker.CameraErrorHandler}
  135. final CameraErrorHandler? onError;
  136. /// {@macro wechat_camera_picker.XFileCapturedCallback}
  137. final XFileCapturedCallback? onXFileCaptured;
  138. /// The callback when the recording is not met the minimum recording duration.
  139. /// 录制时长未达到最小时长时的回调方法。
  140. final VoidCallback? onMinimumRecordDurationNotMet;
  141. /// The callback when the picture or the video is confirmed as picked.
  142. /// 拍照或录像确认时的回调方法。
  143. final void Function(AssetEntity)? onPickConfirmed;
  144. /// The permission request option when saving the captured file using
  145. /// the `photo_manager` package.
  146. /// 使用 `photo_manager` 保存拍摄的文件的权限请求配置。
  147. final PermissionRequestOption? permissionRequestOption;
  148. }