@@ -121,15 +121,15 @@ class CameraPicker extends StatefulWidget {
121
121
class CameraPickerState extends State <CameraPicker > {
122
122
/// The [Duration] for record detection. (200ms)
123
123
/// 检测是否开始录制的时长 (200毫秒)
124
- final Duration recordDetectDuration = kThemeChangeDuration ;
124
+ final Duration recordDetectDuration = 200. milliseconds ;
125
125
126
126
/// Available cameras.
127
127
/// 可用的相机实例
128
128
List <CameraDescription > cameras;
129
129
130
130
/// The controller for the current camera.
131
131
/// 当前相机实例的控制器
132
- CameraController controller ;
132
+ CameraController cameraController ;
133
133
134
134
/// The index of the current cameras. Defaults to `0` .
135
135
/// 当前相机的索引。默认为0
@@ -139,10 +139,6 @@ class CameraPickerState extends State<CameraPicker> {
139
139
/// 临时文件会存放的目录
140
140
String cacheFilePath;
141
141
142
- /// The path of the taken file.
143
- /// 拍照文件的路径。
144
- String takenFilePath;
145
-
146
142
/// Whether the [shootingButton] should animate according to the gesture.
147
143
/// 拍照按钮是否需要执行动画
148
144
///
@@ -168,7 +164,7 @@ class CameraPickerState extends State<CameraPicker> {
168
164
169
165
/// Whether the current [CameraDescription] initialized.
170
166
/// 当前的相机实例是否已完成初始化
171
- bool get isInitialized => controller ? .value? .isInitialized ?? false ;
167
+ bool get isInitialized => cameraController ? .value? .isInitialized ?? false ;
172
168
173
169
/// Whether the taken file should be kept in local. (A non-null wrapper)
174
170
/// 拍照的文件是否应该保存在本地(非空包装)
@@ -178,10 +174,31 @@ class CameraPickerState extends State<CameraPicker> {
178
174
/// 选择器是否可以录像(非空包装)
179
175
bool get isAllowRecording => widget.isAllowRecording ?? false ;
180
176
177
+ /// The path of the taken picture file.
178
+ /// 拍照文件的路径
179
+ String takenPictureFilePath;
180
+
181
+ /// The path of the taken video file.
182
+ /// 录制文件的路径
183
+ String takenVideoFilePath;
184
+
185
+ /// The [File] instance of the taken picture.
186
+ /// 拍照文件的 [File] 实例
187
+ File get takenPictureFile => File (takenPictureFilePath);
188
+
189
+ /// The [File] instance of the taken video.
190
+ /// 录制文件的 [File] 实例
191
+ File get takenVideoFile => File (takenVideoFilePath);
192
+
181
193
/// A getter to the current [CameraDescription] .
182
194
/// 获取当前相机实例
183
195
CameraDescription get currentCamera => cameras? .elementAt (currentCameraIndex);
184
196
197
+ /// Theme data for the picker.
198
+ /// 选择器的主题
199
+ ///
200
+ /// If there's no theme provided from the user, use [CameraPicker.themeData] .
201
+ /// 如果用户未提供主题,
185
202
ThemeData _theme;
186
203
187
204
/// Get [ThemeData] of the [AssetPicker] through [Constants.pickerKey] .
@@ -206,7 +223,7 @@ class CameraPickerState extends State<CameraPicker> {
206
223
@override
207
224
void dispose () {
208
225
SystemChrome .setEnabledSystemUIOverlays (SystemUiOverlay .values);
209
- controller ? .dispose ();
226
+ cameraController ? .dispose ();
210
227
super .dispose ();
211
228
}
212
229
@@ -235,7 +252,7 @@ class CameraPickerState extends State<CameraPicker> {
235
252
/// Initialize cameras instances.
236
253
/// 初始化相机实例
237
254
Future <void > initCameras ({CameraDescription cameraDescription}) async {
238
- controller ? .dispose ();
255
+ cameraController ? .dispose ();
239
256
240
257
/// When it's null, which means this is the first time initializing the cameras.
241
258
/// So cameras should fetch.
@@ -252,11 +269,11 @@ class CameraPickerState extends State<CameraPicker> {
252
269
253
270
/// Initialize the controller with the max resolution preset.
254
271
/// - No one want the lower resolutions. :)
255
- controller = CameraController (
272
+ cameraController = CameraController (
256
273
cameraDescription ?? cameras[0 ],
257
274
ResolutionPreset .max,
258
275
);
259
- controller .initialize ().then ((dynamic _) {
276
+ cameraController .initialize ().then ((dynamic _) {
260
277
if (mounted) {
261
278
setState (() {});
262
279
}
@@ -284,11 +301,11 @@ class CameraPickerState extends State<CameraPicker> {
284
301
/// taking pictures.
285
302
/// 仅当初始化成功且相机未在拍照时拍照。
286
303
Future <void > takePicture () async {
287
- if (isInitialized && ! controller .value.isTakingPicture) {
304
+ if (isInitialized && ! cameraController .value.isTakingPicture) {
288
305
try {
289
306
final String path = '${cacheFilePath }_$currentTimeStamp .jpg' ;
290
- await controller .takePicture (path);
291
- takenFilePath = path;
307
+ await cameraController .takePicture (path);
308
+ takenPictureFilePath = path;
292
309
if (mounted) {
293
310
setState (() {});
294
311
}
@@ -301,9 +318,9 @@ class CameraPickerState extends State<CameraPicker> {
301
318
/// Make sure the [takenFilePath] is `null` before pop.
302
319
/// Otherwise, make it `null` .
303
320
Future <bool > clearTakenFileBeforePop () async {
304
- if (takenFilePath != null ) {
321
+ if (takenPictureFilePath != null ) {
305
322
setState (() {
306
- takenFilePath = null ;
323
+ takenPictureFilePath = null ;
307
324
});
308
325
return false ;
309
326
}
@@ -316,11 +333,11 @@ class CameraPickerState extends State<CameraPicker> {
316
333
/// no side effects if popping `null` because the parent picker will ignore it.
317
334
Future <void > createAssetEntityAndPop () async {
318
335
try {
319
- final File file = File (takenFilePath) ;
336
+ final File file = takenPictureFile ;
320
337
final Uint8List data = await file.readAsBytes ();
321
338
final AssetEntity entity = await PhotoManager .editor.saveImage (
322
339
data,
323
- title: takenFilePath ,
340
+ title: takenPictureFilePath ,
324
341
);
325
342
if (! shouldKeptInLocal) {
326
343
file.delete ();
@@ -394,7 +411,9 @@ class CameraPickerState extends State<CameraPicker> {
394
411
child: Row (
395
412
children: < Widget > [
396
413
Expanded (
397
- child: ! isRecording ? Center (child: backButton) : const SizedBox .shrink (),
414
+ child: ! isRecording
415
+ ? Center (child: backButton)
416
+ : const SizedBox .shrink (),
398
417
),
399
418
Expanded (child: Center (child: shootingButton)),
400
419
const Spacer (),
@@ -514,7 +533,7 @@ class CameraPickerState extends State<CameraPicker> {
514
533
color: Colors .black,
515
534
child: Stack (
516
535
children: < Widget > [
517
- Positioned .fill (child: Image .file (File (takenFilePath) )),
536
+ Positioned .fill (child: Image .file (takenPictureFile )),
518
537
SafeArea (
519
538
child: Padding (
520
539
padding: const EdgeInsets .symmetric (
@@ -551,9 +570,9 @@ class CameraPickerState extends State<CameraPicker> {
551
570
return InkWell (
552
571
borderRadius: maxBorderRadius,
553
572
onTap: () {
554
- File (takenFilePath) .delete ();
573
+ takenPictureFile .delete ();
555
574
setState (() {
556
- takenFilePath = null ;
575
+ takenPictureFilePath = null ;
557
576
});
558
577
},
559
578
child: Container (
@@ -612,8 +631,8 @@ class CameraPickerState extends State<CameraPicker> {
612
631
if (isInitialized)
613
632
Center (
614
633
child: AspectRatio (
615
- aspectRatio: controller .value.aspectRatio,
616
- child: CameraPreview (controller ),
634
+ aspectRatio: cameraController .value.aspectRatio,
635
+ child: CameraPreview (cameraController ),
617
636
),
618
637
)
619
638
else
@@ -631,7 +650,7 @@ class CameraPickerState extends State<CameraPicker> {
631
650
),
632
651
),
633
652
),
634
- if (takenFilePath != null ) takenFilePreviewWidget,
653
+ if (takenPictureFilePath != null ) takenFilePreviewWidget,
635
654
],
636
655
),
637
656
),
0 commit comments