@@ -13,7 +13,17 @@ part 'camera_image.dart';
13
13
14
14
final MethodChannel _channel = const MethodChannel ('plugins.flutter.io/camera' );
15
15
16
- enum CameraLensDirection { front, back, external }
16
+ /// The direction the camera is facing.
17
+ enum CameraLensDirection {
18
+ /// Front facing camera (a user looking at the screen is seen by the camera).
19
+ front,
20
+
21
+ /// Back facing camera (a user looking at the screen is not seen by the camera).
22
+ back,
23
+
24
+ /// External camera which may not be mounted to the device.
25
+ external ,
26
+ }
17
27
18
28
/// Affect the quality of video recording and image capture:
19
29
///
@@ -38,6 +48,9 @@ enum ResolutionPreset {
38
48
max,
39
49
}
40
50
51
+ /// Signature for a callback receiving the a camera image.
52
+ ///
53
+ /// This is used by [CameraController.startImageStream] .
41
54
// ignore: inference_failure_on_function_return_type
42
55
typedef onLatestImageAvailable = Function (CameraImage image);
43
56
@@ -91,10 +104,15 @@ Future<List<CameraDescription>> availableCameras() async {
91
104
}
92
105
}
93
106
107
+ /// Properties of a camera device.
94
108
class CameraDescription {
109
+ /// Creates a new camera description with the given properties.
95
110
CameraDescription ({this .name, this .lensDirection, this .sensorOrientation});
96
111
112
+ /// The name of the camera device.
97
113
final String name;
114
+
115
+ /// The direction the camera is facing.
98
116
final CameraLensDirection lensDirection;
99
117
100
118
/// Clockwise angle through which the output image needs to be rotated to be upright on the device screen in its native orientation.
@@ -126,19 +144,27 @@ class CameraDescription {
126
144
127
145
/// This is thrown when the plugin reports an error.
128
146
class CameraException implements Exception {
147
+ /// Creates a new camera exception with the given error code and description.
129
148
CameraException (this .code, this .description);
130
149
150
+ /// Error code.
151
+ // TODO(bparrishMines): Document possible error codes.
152
+ // https://github.com/flutter/flutter/issues/69298
131
153
String code;
154
+
155
+ /// Textual description of the error.
132
156
String description;
133
157
134
158
@override
135
159
String toString () => '$runtimeType ($code , $description )' ;
136
160
}
137
161
138
- // Build the UI texture view of the video data with textureId .
162
+ /// A widget showing a live camera preview .
139
163
class CameraPreview extends StatelessWidget {
164
+ /// Creates a preview widget for the given camera controller.
140
165
const CameraPreview (this .controller);
141
166
167
+ /// The controller for the camera that the preview is shown for.
142
168
final CameraController controller;
143
169
144
170
@override
@@ -151,6 +177,7 @@ class CameraPreview extends StatelessWidget {
151
177
152
178
/// The state of a [CameraController] .
153
179
class CameraValue {
180
+ /// Creates a new camera controller state.
154
181
const CameraValue ({
155
182
this .isInitialized,
156
183
this .errorDescription,
@@ -161,6 +188,7 @@ class CameraValue {
161
188
bool isRecordingPaused,
162
189
}) : _isRecordingPaused = isRecordingPaused;
163
190
191
+ /// Creates a new camera controller state for an uninitialzed controller.
164
192
const CameraValue .uninitialized ()
165
193
: this (
166
194
isInitialized: false ,
@@ -187,6 +215,10 @@ class CameraValue {
187
215
/// True when camera [isRecordingVideo] and recording is paused.
188
216
bool get isRecordingPaused => isRecordingVideo && _isRecordingPaused;
189
217
218
+ /// Description of an error state.
219
+ ///
220
+ /// This is null while the controller is not in an error state.
221
+ /// When [hasError] is true this contains the error description.
190
222
final String errorDescription;
191
223
192
224
/// The size of the preview in pixels.
@@ -199,8 +231,15 @@ class CameraValue {
199
231
/// Can only be called when [initialize] is done.
200
232
double get aspectRatio => previewSize.height / previewSize.width;
201
233
234
+ /// Whether the controller is in an error state.
235
+ ///
236
+ /// When true [errorDescription] describes the error.
202
237
bool get hasError => errorDescription != null ;
203
238
239
+ /// Creates a modified copy of the object.
240
+ ///
241
+ /// Explicitly specified fields get the specified value, all other fields get
242
+ /// the same value of the current object.
204
243
CameraValue copyWith ({
205
244
bool isInitialized,
206
245
bool isRecordingVideo,
@@ -241,13 +280,22 @@ class CameraValue {
241
280
///
242
281
/// To show the camera preview on the screen use a [CameraPreview] widget.
243
282
class CameraController extends ValueNotifier <CameraValue > {
283
+ /// Creates a new camera controller in an uninitialized state.
244
284
CameraController (
245
285
this .description,
246
286
this .resolutionPreset, {
247
287
this .enableAudio = true ,
248
288
}) : super (const CameraValue .uninitialized ());
249
289
290
+ /// The properties of the camera device controlled by this controller.
250
291
final CameraDescription description;
292
+
293
+ /// The resolution this controller is targeting.
294
+ ///
295
+ /// This resolution preset is not guaranteed to be available on the device,
296
+ /// if unavailable a lower resolution will be used.
297
+ ///
298
+ /// See also: [ResolutionPreset] .
251
299
final ResolutionPreset resolutionPreset;
252
300
253
301
/// Whether to include audio when recording a video.
0 commit comments