@@ -32,19 +32,19 @@ Future<List<CameraDescription>> availableCameras() async {
32
32
class CameraValue {
33
33
/// Creates a new camera controller state.
34
34
const CameraValue ({
35
- this .isInitialized,
35
+ required this .isInitialized,
36
36
this .errorDescription,
37
37
this .previewSize,
38
- this .isRecordingVideo,
39
- this .isTakingPicture,
40
- this .isStreamingImages,
41
- bool isRecordingPaused,
42
- this .flashMode,
43
- this .exposureMode,
44
- this .focusMode,
45
- this .exposurePointSupported,
46
- this .focusPointSupported,
47
- this .deviceOrientation,
38
+ required this .isRecordingVideo,
39
+ required this .isTakingPicture,
40
+ required this .isStreamingImages,
41
+ required bool isRecordingPaused,
42
+ required this .flashMode,
43
+ required this .exposureMode,
44
+ required this .focusMode,
45
+ required this .exposurePointSupported,
46
+ required this .focusPointSupported,
47
+ required this .deviceOrientation,
48
48
this .lockedCaptureOrientation,
49
49
this .recordingOrientation,
50
50
}) : _isRecordingPaused = isRecordingPaused;
@@ -58,7 +58,9 @@ class CameraValue {
58
58
isStreamingImages: false ,
59
59
isRecordingPaused: false ,
60
60
flashMode: FlashMode .auto,
61
+ exposureMode: ExposureMode .auto,
61
62
exposurePointSupported: false ,
63
+ focusMode: FocusMode .auto,
62
64
focusPointSupported: false ,
63
65
deviceOrientation: DeviceOrientation .portraitUp,
64
66
);
@@ -84,17 +86,17 @@ class CameraValue {
84
86
///
85
87
/// This is null while the controller is not in an error state.
86
88
/// When [hasError] is true this contains the error description.
87
- final String errorDescription;
89
+ final String ? errorDescription;
88
90
89
91
/// The size of the preview in pixels.
90
92
///
91
- /// Is `null` until [isInitialized] is `true` .
92
- final Size previewSize;
93
+ /// Is `null` until [isInitialized] is `true` .
94
+ final Size ? previewSize;
93
95
94
96
/// Convenience getter for `previewSize.width / previewSize.height` .
95
97
///
96
98
/// Can only be called when [initialize] is done.
97
- double get aspectRatio => previewSize.width / previewSize.height;
99
+ double get aspectRatio => previewSize! .width / previewSize! .height;
98
100
99
101
/// Whether the controller is in an error state.
100
102
///
@@ -120,34 +122,34 @@ class CameraValue {
120
122
final DeviceOrientation deviceOrientation;
121
123
122
124
/// The currently locked capture orientation.
123
- final DeviceOrientation lockedCaptureOrientation;
125
+ final DeviceOrientation ? lockedCaptureOrientation;
124
126
125
127
/// Whether the capture orientation is currently locked.
126
128
bool get isCaptureOrientationLocked => lockedCaptureOrientation != null ;
127
129
128
130
/// The orientation of the currently running video recording.
129
- final DeviceOrientation recordingOrientation;
131
+ final DeviceOrientation ? recordingOrientation;
130
132
131
133
/// Creates a modified copy of the object.
132
134
///
133
135
/// Explicitly specified fields get the specified value, all other fields get
134
136
/// the same value of the current object.
135
137
CameraValue copyWith ({
136
- bool isInitialized,
137
- bool isRecordingVideo,
138
- bool isTakingPicture,
139
- bool isStreamingImages,
140
- String errorDescription,
141
- Size previewSize,
142
- bool isRecordingPaused,
143
- FlashMode flashMode,
144
- ExposureMode exposureMode,
145
- FocusMode focusMode,
146
- bool exposurePointSupported,
147
- bool focusPointSupported,
148
- DeviceOrientation deviceOrientation,
149
- Optional <DeviceOrientation > lockedCaptureOrientation,
150
- Optional <DeviceOrientation > recordingOrientation,
138
+ bool ? isInitialized,
139
+ bool ? isRecordingVideo,
140
+ bool ? isTakingPicture,
141
+ bool ? isStreamingImages,
142
+ String ? errorDescription,
143
+ Size ? previewSize,
144
+ bool ? isRecordingPaused,
145
+ FlashMode ? flashMode,
146
+ ExposureMode ? exposureMode,
147
+ FocusMode ? focusMode,
148
+ bool ? exposurePointSupported,
149
+ bool ? focusPointSupported,
150
+ DeviceOrientation ? deviceOrientation,
151
+ Optional <DeviceOrientation >? lockedCaptureOrientation,
152
+ Optional <DeviceOrientation >? recordingOrientation,
151
153
}) {
152
154
return CameraValue (
153
155
isInitialized: isInitialized ?? this .isInitialized,
@@ -225,13 +227,17 @@ class CameraController extends ValueNotifier<CameraValue> {
225
227
/// The [ImageFormatGroup] describes the output of the raw image format.
226
228
///
227
229
/// When null the imageFormat will fallback to the platforms default.
228
- final ImageFormatGroup imageFormatGroup;
230
+ final ImageFormatGroup ? imageFormatGroup;
231
+
232
+ /// The id of a camera that hasn't been initialized.
233
+ @visibleForTesting
234
+ static const int kUninitializedCameraId = - 1 ;
235
+ int _cameraId = kUninitializedCameraId;
229
236
230
- int _cameraId;
231
237
bool _isDisposed = false ;
232
- StreamSubscription <dynamic > _imageStreamSubscription;
233
- FutureOr <bool > _initCalled;
234
- StreamSubscription _deviceOrientationSubscription;
238
+ StreamSubscription <dynamic >? _imageStreamSubscription;
239
+ FutureOr <bool >? _initCalled;
240
+ StreamSubscription ? _deviceOrientationSubscription;
235
241
236
242
/// Checks whether [CameraController.dispose] has completed successfully.
237
243
///
@@ -278,7 +284,7 @@ class CameraController extends ValueNotifier<CameraValue> {
278
284
279
285
await CameraPlatform .instance.initializeCamera (
280
286
_cameraId,
281
- imageFormatGroup: imageFormatGroup,
287
+ imageFormatGroup: imageFormatGroup ?? ImageFormatGroup .unknown ,
282
288
);
283
289
284
290
value = value.copyWith (
@@ -422,7 +428,7 @@ class CameraController extends ValueNotifier<CameraValue> {
422
428
throw CameraException (e.code, e.message);
423
429
}
424
430
425
- await _imageStreamSubscription.cancel ();
431
+ await _imageStreamSubscription? .cancel ();
426
432
_imageStreamSubscription = null ;
427
433
}
428
434
@@ -583,12 +589,16 @@ class CameraController extends ValueNotifier<CameraValue> {
583
589
}
584
590
585
591
/// Sets the exposure point for automatically determining the exposure value.
586
- Future <void > setExposurePoint (Offset point) async {
592
+ ///
593
+ /// Supplying a `null` value will reset the exposure point to it's default
594
+ /// value.
595
+ Future <void > setExposurePoint (Offset ? point) async {
587
596
if (point != null &&
588
597
(point.dx < 0 || point.dx > 1 || point.dy < 0 || point.dy > 1 )) {
589
598
throw ArgumentError (
590
599
'The values of point should be anywhere between (0,0) and (1,1).' );
591
600
}
601
+
592
602
try {
593
603
await CameraPlatform .instance.setExposurePoint (
594
604
_cameraId,
@@ -682,7 +692,7 @@ class CameraController extends ValueNotifier<CameraValue> {
682
692
/// Locks the capture orientation.
683
693
///
684
694
/// If [orientation] is omitted, the current device orientation is used.
685
- Future <void > lockCaptureOrientation ([DeviceOrientation orientation]) async {
695
+ Future <void > lockCaptureOrientation ([DeviceOrientation ? orientation]) async {
686
696
try {
687
697
await CameraPlatform .instance.lockCaptureOrientation (
688
698
_cameraId, orientation ?? value.deviceOrientation);
@@ -715,7 +725,10 @@ class CameraController extends ValueNotifier<CameraValue> {
715
725
}
716
726
717
727
/// Sets the focus point for automatically determining the focus value.
718
- Future <void > setFocusPoint (Offset point) async {
728
+ ///
729
+ /// Supplying a `null` value will reset the focus point to it's default
730
+ /// value.
731
+ Future <void > setFocusPoint (Offset ? point) async {
719
732
if (point != null &&
720
733
(point.dx < 0 || point.dx > 1 || point.dy < 0 || point.dy > 1 )) {
721
734
throw ArgumentError (
0 commit comments