Skip to content

Commit bddabb4

Browse files
committed
🔥 Clean codes
1 parent 34c6e54 commit bddabb4

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

lib/src/widgets/camera_picker.dart

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -225,24 +225,12 @@ class CameraPickerState extends State<CameraPicker>
225225
bool get shouldPrepareForVideoRecording =>
226226
enableRecording && enableAudio && Platform.isIOS;
227227

228-
bool get enableSetExposure => config.enableSetExposure;
229-
230-
bool get enableExposureControlOnPoint => config.enableExposureControlOnPoint;
231-
232-
bool get enablePinchToZoom => config.enablePinchToZoom;
233-
234228
bool get enablePullToZoomInRecord =>
235229
enableRecording && config.enablePullToZoomInRecord;
236230

237-
bool get shouldDeletePreviewFile => config.shouldDeletePreviewFile;
238-
239-
bool get shouldAutoPreviewVideo => config.shouldAutoPreviewVideo;
240-
241-
Duration? get maximumRecordingDuration => config.maximumRecordingDuration;
242-
243231
/// Whether the recording restricted to a specific duration.
244232
/// 录像是否有限制的时长
245-
bool get isRecordingRestricted => maximumRecordingDuration != null;
233+
bool get isRecordingRestricted => config.maximumRecordingDuration != null;
246234

247235
/// A getter to the current [CameraDescription].
248236
/// 获取当前相机实例
@@ -526,7 +514,6 @@ class CameraPickerState extends State<CameraPicker>
526514
if (_pointers != 2) {
527515
return;
528516
}
529-
530517
zoom(details.scale);
531518
}
532519

@@ -753,7 +740,7 @@ class CameraPickerState extends State<CameraPicker>
753740
try {
754741
await controller.startVideoRecording();
755742
if (isRecordingRestricted) {
756-
_recordCountdownTimer = Timer(maximumRecordingDuration!, () {
743+
_recordCountdownTimer = Timer(config.maximumRecordingDuration!, () {
757744
stopRecordingVideo();
758745
});
759746
}
@@ -829,8 +816,8 @@ class CameraPickerState extends State<CameraPicker>
829816
pickerType: viewType,
830817
previewXFile: file,
831818
theme: theme,
832-
shouldDeletePreviewFile: shouldDeletePreviewFile,
833-
shouldAutoPreviewVideo: shouldAutoPreviewVideo,
819+
shouldDeletePreviewFile: config.shouldDeletePreviewFile,
820+
shouldAutoPreviewVideo: config.shouldAutoPreviewVideo,
834821
onEntitySaving: config.onEntitySaving,
835822
onError: config.onError,
836823
);
@@ -1096,7 +1083,7 @@ class CameraPickerState extends State<CameraPicker>
10961083
(_controller?.value.isRecordingVideo ?? false) &&
10971084
isRecordingRestricted,
10981085
builder: (_, __) => CircularProgressBar(
1099-
duration: maximumRecordingDuration!,
1086+
duration: config.maximumRecordingDuration!,
11001087
outerRadius: outerSize.width,
11011088
ringsColor: theme.indicatorColor,
11021089
ringsWidth: 2,
@@ -1233,11 +1220,9 @@ class CameraPickerState extends State<CameraPicker>
12331220
const double controllerWidth = 20;
12341221
final double pointWidth = constraints.maxWidth / 5;
12351222
final double exposureControlWidth =
1236-
enableExposureControlOnPoint ? controllerWidth : 0;
1223+
config.enableExposureControlOnPoint ? controllerWidth : 0;
12371224
final double width = pointWidth + exposureControlWidth + 2;
1238-
12391225
final bool shouldReverseLayout = point.dx > constraints.maxWidth / 4 * 3;
1240-
12411226
final double effectiveLeft = math.min(
12421227
constraints.maxWidth - width,
12431228
math.max(0, point.dx - width / 2),
@@ -1246,7 +1231,6 @@ class CameraPickerState extends State<CameraPicker>
12461231
constraints.maxHeight - pointWidth * 3,
12471232
math.max(0, point.dy - pointWidth * 3 / 2),
12481233
);
1249-
12501234
return Positioned(
12511235
left: effectiveLeft,
12521236
top: effectiveTop,
@@ -1262,8 +1246,8 @@ class CameraPickerState extends State<CameraPicker>
12621246
size: pointWidth,
12631247
color: theme.iconTheme.color!,
12641248
),
1265-
if (enableExposureControlOnPoint) const SizedBox(width: 2),
1266-
if (enableExposureControlOnPoint)
1249+
if (config.enableExposureControlOnPoint) const SizedBox(width: 2),
1250+
if (config.enableExposureControlOnPoint)
12671251
SizedBox.fromSize(
12681252
size: Size(exposureControlWidth, pointWidth * 3),
12691253
child: _buildControl(controllerWidth, pointWidth * 3),
@@ -1336,8 +1320,8 @@ class CameraPickerState extends State<CameraPicker>
13361320
onPointerDown: (_) => _pointers++,
13371321
onPointerUp: (_) => _pointers--,
13381322
child: GestureDetector(
1339-
onScaleStart: enablePinchToZoom ? _handleScaleStart : null,
1340-
onScaleUpdate: enablePinchToZoom ? _handleScaleUpdate : null,
1323+
onScaleStart: config.enablePinchToZoom ? _handleScaleStart : null,
1324+
onScaleUpdate: config.enablePinchToZoom ? _handleScaleUpdate : null,
13411325
// Enabled cameras switching by default if we have multiple cameras.
13421326
onDoubleTap: cameras.length > 1 ? switchCameras : null,
13431327
child: _controller != null
@@ -1444,14 +1428,14 @@ class CameraPickerState extends State<CameraPicker>
14441428
children: <Widget>[
14451429
ExcludeSemantics(
14461430
child: _initializeWrapper(
1447-
builder: (CameraValue value, __) => _cameraBuilder(
1431+
builder: (CameraValue value, Widget? w) => _cameraBuilder(
14481432
context: c,
14491433
value: value,
14501434
constraints: constraints,
14511435
),
14521436
),
14531437
),
1454-
if (enableSetExposure)
1438+
if (config.enableSetExposure)
14551439
_exposureDetectorWidget(c, constraints),
14561440
_initializeWrapper(
14571441
builder: (CameraValue cameraValue, Widget? w) {

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ dependencies:
1515
camera: ^0.9.6
1616
camera_platform_interface: ^2.1.5
1717
path: ^1.8.0
18-
path_provider: ^2.0.8
1918
photo_manager: ^2.1.0+2
2019
video_player: ^2.3.2

0 commit comments

Comments
 (0)