Skip to content

Commit 5c1668d

Browse files
committed
🎨 Stripping variables' name.
1 parent 5d5b523 commit 5c1668d

File tree

1 file changed

+44
-25
lines changed

1 file changed

+44
-25
lines changed

lib/src/widget/camera_picker.dart

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ class CameraPicker extends StatefulWidget {
121121
class CameraPickerState extends State<CameraPicker> {
122122
/// The [Duration] for record detection. (200ms)
123123
/// 检测是否开始录制的时长 (200毫秒)
124-
final Duration recordDetectDuration = kThemeChangeDuration;
124+
final Duration recordDetectDuration = 200.milliseconds;
125125

126126
/// Available cameras.
127127
/// 可用的相机实例
128128
List<CameraDescription> cameras;
129129

130130
/// The controller for the current camera.
131131
/// 当前相机实例的控制器
132-
CameraController controller;
132+
CameraController cameraController;
133133

134134
/// The index of the current cameras. Defaults to `0`.
135135
/// 当前相机的索引。默认为0
@@ -139,10 +139,6 @@ class CameraPickerState extends State<CameraPicker> {
139139
/// 临时文件会存放的目录
140140
String cacheFilePath;
141141

142-
/// The path of the taken file.
143-
/// 拍照文件的路径。
144-
String takenFilePath;
145-
146142
/// Whether the [shootingButton] should animate according to the gesture.
147143
/// 拍照按钮是否需要执行动画
148144
///
@@ -168,7 +164,7 @@ class CameraPickerState extends State<CameraPicker> {
168164

169165
/// Whether the current [CameraDescription] initialized.
170166
/// 当前的相机实例是否已完成初始化
171-
bool get isInitialized => controller?.value?.isInitialized ?? false;
167+
bool get isInitialized => cameraController?.value?.isInitialized ?? false;
172168

173169
/// Whether the taken file should be kept in local. (A non-null wrapper)
174170
/// 拍照的文件是否应该保存在本地(非空包装)
@@ -178,10 +174,31 @@ class CameraPickerState extends State<CameraPicker> {
178174
/// 选择器是否可以录像(非空包装)
179175
bool get isAllowRecording => widget.isAllowRecording ?? false;
180176

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+
181193
/// A getter to the current [CameraDescription].
182194
/// 获取当前相机实例
183195
CameraDescription get currentCamera => cameras?.elementAt(currentCameraIndex);
184196

197+
/// Theme data for the picker.
198+
/// 选择器的主题
199+
///
200+
/// If there's no theme provided from the user, use [CameraPicker.themeData] .
201+
/// 如果用户未提供主题,
185202
ThemeData _theme;
186203

187204
/// Get [ThemeData] of the [AssetPicker] through [Constants.pickerKey].
@@ -206,7 +223,7 @@ class CameraPickerState extends State<CameraPicker> {
206223
@override
207224
void dispose() {
208225
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
209-
controller?.dispose();
226+
cameraController?.dispose();
210227
super.dispose();
211228
}
212229

@@ -235,7 +252,7 @@ class CameraPickerState extends State<CameraPicker> {
235252
/// Initialize cameras instances.
236253
/// 初始化相机实例
237254
Future<void> initCameras({CameraDescription cameraDescription}) async {
238-
controller?.dispose();
255+
cameraController?.dispose();
239256

240257
/// When it's null, which means this is the first time initializing the cameras.
241258
/// So cameras should fetch.
@@ -252,11 +269,11 @@ class CameraPickerState extends State<CameraPicker> {
252269

253270
/// Initialize the controller with the max resolution preset.
254271
/// - No one want the lower resolutions. :)
255-
controller = CameraController(
272+
cameraController = CameraController(
256273
cameraDescription ?? cameras[0],
257274
ResolutionPreset.max,
258275
);
259-
controller.initialize().then((dynamic _) {
276+
cameraController.initialize().then((dynamic _) {
260277
if (mounted) {
261278
setState(() {});
262279
}
@@ -284,11 +301,11 @@ class CameraPickerState extends State<CameraPicker> {
284301
/// taking pictures.
285302
/// 仅当初始化成功且相机未在拍照时拍照。
286303
Future<void> takePicture() async {
287-
if (isInitialized && !controller.value.isTakingPicture) {
304+
if (isInitialized && !cameraController.value.isTakingPicture) {
288305
try {
289306
final String path = '${cacheFilePath}_$currentTimeStamp.jpg';
290-
await controller.takePicture(path);
291-
takenFilePath = path;
307+
await cameraController.takePicture(path);
308+
takenPictureFilePath = path;
292309
if (mounted) {
293310
setState(() {});
294311
}
@@ -301,9 +318,9 @@ class CameraPickerState extends State<CameraPicker> {
301318
/// Make sure the [takenFilePath] is `null` before pop.
302319
/// Otherwise, make it `null` .
303320
Future<bool> clearTakenFileBeforePop() async {
304-
if (takenFilePath != null) {
321+
if (takenPictureFilePath != null) {
305322
setState(() {
306-
takenFilePath = null;
323+
takenPictureFilePath = null;
307324
});
308325
return false;
309326
}
@@ -316,11 +333,11 @@ class CameraPickerState extends State<CameraPicker> {
316333
/// no side effects if popping `null` because the parent picker will ignore it.
317334
Future<void> createAssetEntityAndPop() async {
318335
try {
319-
final File file = File(takenFilePath);
336+
final File file = takenPictureFile;
320337
final Uint8List data = await file.readAsBytes();
321338
final AssetEntity entity = await PhotoManager.editor.saveImage(
322339
data,
323-
title: takenFilePath,
340+
title: takenPictureFilePath,
324341
);
325342
if (!shouldKeptInLocal) {
326343
file.delete();
@@ -394,7 +411,9 @@ class CameraPickerState extends State<CameraPicker> {
394411
child: Row(
395412
children: <Widget>[
396413
Expanded(
397-
child: !isRecording ? Center(child: backButton) : const SizedBox.shrink(),
414+
child: !isRecording
415+
? Center(child: backButton)
416+
: const SizedBox.shrink(),
398417
),
399418
Expanded(child: Center(child: shootingButton)),
400419
const Spacer(),
@@ -514,7 +533,7 @@ class CameraPickerState extends State<CameraPicker> {
514533
color: Colors.black,
515534
child: Stack(
516535
children: <Widget>[
517-
Positioned.fill(child: Image.file(File(takenFilePath))),
536+
Positioned.fill(child: Image.file(takenPictureFile)),
518537
SafeArea(
519538
child: Padding(
520539
padding: const EdgeInsets.symmetric(
@@ -551,9 +570,9 @@ class CameraPickerState extends State<CameraPicker> {
551570
return InkWell(
552571
borderRadius: maxBorderRadius,
553572
onTap: () {
554-
File(takenFilePath).delete();
573+
takenPictureFile.delete();
555574
setState(() {
556-
takenFilePath = null;
575+
takenPictureFilePath = null;
557576
});
558577
},
559578
child: Container(
@@ -612,8 +631,8 @@ class CameraPickerState extends State<CameraPicker> {
612631
if (isInitialized)
613632
Center(
614633
child: AspectRatio(
615-
aspectRatio: controller.value.aspectRatio,
616-
child: CameraPreview(controller),
634+
aspectRatio: cameraController.value.aspectRatio,
635+
child: CameraPreview(cameraController),
617636
),
618637
)
619638
else
@@ -631,7 +650,7 @@ class CameraPickerState extends State<CameraPicker> {
631650
),
632651
),
633652
),
634-
if (takenFilePath != null) takenFilePreviewWidget,
653+
if (takenPictureFilePath != null) takenFilePreviewWidget,
635654
],
636655
),
637656
),

0 commit comments

Comments
 (0)