@@ -49,14 +49,15 @@ class CameraValue {
4949 required this .exposurePointSupported,
5050 required this .focusPointSupported,
5151 required this .deviceOrientation,
52+ required this .description,
5253 this .lockedCaptureOrientation,
5354 this .recordingOrientation,
5455 this .isPreviewPaused = false ,
5556 this .previewPauseOrientation,
5657 }) : _isRecordingPaused = isRecordingPaused;
5758
5859 /// Creates a new camera controller state for an uninitialized controller.
59- const CameraValue .uninitialized ()
60+ const CameraValue .uninitialized (CameraDescription description )
6061 : this (
6162 isInitialized: false ,
6263 isRecordingVideo: false ,
@@ -70,6 +71,7 @@ class CameraValue {
7071 focusPointSupported: false ,
7172 deviceOrientation: DeviceOrientation .portraitUp,
7273 isPreviewPaused: false ,
74+ description: description,
7375 );
7476
7577 /// True after [CameraController.initialize] has completed successfully.
@@ -143,6 +145,9 @@ class CameraValue {
143145 /// The orientation of the currently running video recording.
144146 final DeviceOrientation ? recordingOrientation;
145147
148+ /// The properties of the camera device controlled by this controller.
149+ final CameraDescription description;
150+
146151 /// Creates a modified copy of the object.
147152 ///
148153 /// Explicitly specified fields get the specified value, all other fields get
@@ -164,6 +169,7 @@ class CameraValue {
164169 Optional <DeviceOrientation >? lockedCaptureOrientation,
165170 Optional <DeviceOrientation >? recordingOrientation,
166171 bool ? isPreviewPaused,
172+ CameraDescription ? description,
167173 Optional <DeviceOrientation >? previewPauseOrientation,
168174 }) {
169175 return CameraValue (
@@ -188,6 +194,7 @@ class CameraValue {
188194 ? this .recordingOrientation
189195 : recordingOrientation.orNull,
190196 isPreviewPaused: isPreviewPaused ?? this .isPreviewPaused,
197+ description: description ?? this .description,
191198 previewPauseOrientation: previewPauseOrientation == null
192199 ? this .previewPauseOrientation
193200 : previewPauseOrientation.orNull,
@@ -211,7 +218,8 @@ class CameraValue {
211218 'lockedCaptureOrientation: $lockedCaptureOrientation , '
212219 'recordingOrientation: $recordingOrientation , '
213220 'isPreviewPaused: $isPreviewPaused , '
214- 'previewPausedOrientation: $previewPauseOrientation )' ;
221+ 'previewPausedOrientation: $previewPauseOrientation , '
222+ 'description: $description )' ;
215223 }
216224}
217225
@@ -225,14 +233,14 @@ class CameraValue {
225233class CameraController extends ValueNotifier <CameraValue > {
226234 /// Creates a new camera controller in an uninitialized state.
227235 CameraController (
228- this . description,
236+ CameraDescription description,
229237 this .resolutionPreset, {
230238 this .enableAudio = true ,
231239 this .imageFormatGroup,
232- }) : super (const CameraValue .uninitialized ());
240+ }) : super (CameraValue .uninitialized (description ));
233241
234242 /// The properties of the camera device controlled by this controller.
235- final CameraDescription description;
243+ CameraDescription get description => value. description;
236244
237245 /// The resolution this controller is targeting.
238246 ///
@@ -274,7 +282,12 @@ class CameraController extends ValueNotifier<CameraValue> {
274282 /// Initializes the camera on the device.
275283 ///
276284 /// Throws a [CameraException] if the initialization fails.
277- Future <void > initialize () async {
285+ Future <void > initialize () => _initializeWithDescription (description);
286+
287+ /// Initializes the camera on the device with the specified description.
288+ ///
289+ /// Throws a [CameraException] if the initialization fails.
290+ Future <void > _initializeWithDescription (CameraDescription description) async {
278291 if (_isDisposed) {
279292 throw CameraException (
280293 'Disposed CameraController' ,
@@ -313,6 +326,7 @@ class CameraController extends ValueNotifier<CameraValue> {
313326
314327 value = value.copyWith (
315328 isInitialized: true ,
329+ description: description,
316330 previewSize: await initializeCompleter.future
317331 .then ((CameraInitializedEvent event) => Size (
318332 event.previewWidth,
@@ -380,6 +394,18 @@ class CameraController extends ValueNotifier<CameraValue> {
380394 }
381395 }
382396
397+ /// Sets the description of the camera.
398+ ///
399+ /// Throws a [CameraException] if setting the description fails.
400+ Future <void > setDescription (CameraDescription description) async {
401+ if (value.isRecordingVideo) {
402+ await CameraPlatform .instance.setDescriptionWhileRecording (description);
403+ value = value.copyWith (description: description);
404+ } else {
405+ await _initializeWithDescription (description);
406+ }
407+ }
408+
383409 /// Captures an image and returns the file where it was saved.
384410 ///
385411 /// Throws a [CameraException] if the capture fails.
0 commit comments