@@ -134,11 +134,6 @@ class CameraPickerState extends State<CameraPicker>
134
134
/// 在开始录像前,最后一次在拍照按钮按下的位置
135
135
Offset ? _lastShootingButtonPressedPosition;
136
136
137
- /// Current exposure mode.
138
- /// 当前曝光模式
139
- final ValueNotifier <ExposureMode > _exposureMode =
140
- ValueNotifier <ExposureMode >(ExposureMode .auto);
141
-
142
137
final ValueNotifier <bool > _isExposureModeDisplays =
143
138
ValueNotifier <bool >(false );
144
139
@@ -288,7 +283,6 @@ class CameraPickerState extends State<CameraPicker>
288
283
_controller? .dispose ();
289
284
_currentExposureOffset.dispose ();
290
285
_lastExposurePoint.dispose ();
291
- _exposureMode.dispose ();
292
286
_isExposureModeDisplays.dispose ();
293
287
_exposurePointDisplayTimer? .cancel ();
294
288
_exposureModeDisplayTimer? .cancel ();
@@ -477,18 +471,24 @@ class CameraPickerState extends State<CameraPicker>
477
471
/// The method to switch between flash modes.
478
472
/// 切换闪光灯模式的方法
479
473
Future <void > switchFlashesMode () async {
474
+ final FlashMode newFlashMode;
480
475
switch (controller.value.flashMode) {
481
476
case FlashMode .off:
482
- await controller. setFlashMode ( FlashMode .auto) ;
477
+ newFlashMode = FlashMode .auto;
483
478
break ;
484
479
case FlashMode .auto:
485
- await controller. setFlashMode ( FlashMode .always) ;
480
+ newFlashMode = FlashMode .always;
486
481
break ;
487
482
case FlashMode .always:
488
483
case FlashMode .torch:
489
- await controller. setFlashMode ( FlashMode .off) ;
484
+ newFlashMode = FlashMode .off;
490
485
break ;
491
486
}
487
+ try {
488
+ await controller.setFlashMode (newFlashMode);
489
+ } catch (e, s) {
490
+ handleErrorWithHandler (e, config.onError, s: s);
491
+ }
492
492
}
493
493
494
494
Future <void > zoom (double scale) async {
@@ -546,19 +546,25 @@ class CameraPickerState extends State<CameraPicker>
546
546
547
547
/// Use the specific [mode] to update the exposure mode.
548
548
/// 设置曝光模式
549
- void switchExposureMode () {
550
- if (_exposureMode.value == ExposureMode .auto) {
551
- _exposureMode.value = ExposureMode .locked;
549
+ Future <void > switchExposureMode () async {
550
+ final ExposureMode mode = controller.value.exposureMode;
551
+ final ExposureMode newMode;
552
+ if (mode == ExposureMode .auto) {
553
+ newMode = ExposureMode .locked;
552
554
} else {
553
- _exposureMode.value = ExposureMode .auto;
555
+ newMode = ExposureMode .auto;
554
556
}
555
557
_exposurePointDisplayTimer? .cancel ();
556
- if (_exposureMode.value == ExposureMode .auto) {
558
+ if (newMode == ExposureMode .auto) {
557
559
_exposurePointDisplayTimer = Timer (const Duration (seconds: 5 ), () {
558
560
_lastExposurePoint.value = null ;
559
561
});
560
562
}
561
- controller.setExposureMode (_exposureMode.value);
563
+ try {
564
+ await controller.setExposureMode (newMode);
565
+ } catch (e, s) {
566
+ handleErrorWithHandler (e, config.onError, s: s);
567
+ }
562
568
_restartModeDisplayTimer ();
563
569
}
564
570
@@ -581,23 +587,22 @@ class CameraPickerState extends State<CameraPicker>
581
587
_lastExposurePoint.value = position;
582
588
_restartPointDisplayTimer ();
583
589
_currentExposureOffset.value = 0 ;
584
- if (_exposureMode.value == ExposureMode .locked) {
585
- await controller.setExposureMode (ExposureMode .auto);
586
- _exposureMode.value = ExposureMode .auto;
587
- }
588
- controller.setExposurePoint (
589
- _lastExposurePoint.value! .scale (
590
+ try {
591
+ if (controller.value.exposureMode == ExposureMode .locked) {
592
+ await controller.setExposureMode (ExposureMode .auto);
593
+ }
594
+ final Offset newPoint = _lastExposurePoint.value! .scale (
590
595
1 / constraints.maxWidth,
591
596
1 / constraints.maxHeight,
592
- ),
593
- );
594
- if (controller.value.focusPointSupported) {
595
- controller.setFocusPoint (
596
- _lastExposurePoint.value! .scale (
597
- 1 / constraints.maxWidth,
598
- 1 / constraints.maxHeight,
599
- ),
600
597
);
598
+ if (controller.value.exposurePointSupported) {
599
+ controller.setExposurePoint (newPoint);
600
+ }
601
+ if (controller.value.focusPointSupported) {
602
+ controller.setFocusPoint (newPoint);
603
+ }
604
+ } catch (e, s) {
605
+ handleErrorWithHandler (e, config.onError, s: s);
601
606
}
602
607
}
603
608
@@ -1185,43 +1190,42 @@ class CameraPickerState extends State<CameraPicker>
1185
1190
1186
1191
/// The area widget for the last exposure point that user manually set.
1187
1192
/// 用户手动设置的曝光点的区域显示
1188
- Widget _focusingAreaWidget (BoxConstraints constraints) {
1193
+ Widget _focusingAreaWidget (
1194
+ CameraValue cameraValue,
1195
+ BoxConstraints constraints,
1196
+ ) {
1189
1197
Widget _buildControl (double size, double height) {
1190
1198
const double verticalGap = 3 ;
1191
- return ValueListenableBuilder <ExposureMode >(
1192
- valueListenable: _exposureMode,
1193
- builder: (_, ExposureMode mode, __) {
1194
- final bool isLocked = mode == ExposureMode .locked;
1195
- return Column (
1196
- children: < Widget > [
1197
- ValueListenableBuilder <bool >(
1198
- valueListenable: _isExposureModeDisplays,
1199
- builder: (_, bool value, Widget ? child) => AnimatedOpacity (
1200
- duration: _kDuration,
1201
- opacity: value ? 1 : 0 ,
1202
- child: child,
1203
- ),
1204
- child: GestureDetector (
1205
- onTap: switchExposureMode,
1206
- child: SizedBox .fromSize (
1207
- size: Size .square (size),
1208
- child: Icon (
1209
- isLocked ? Icons .lock_rounded : Icons .lock_open_rounded,
1210
- size: size,
1211
- color: isLocked ? _lockedColor : null ,
1212
- ),
1213
- ),
1199
+ final ExposureMode exposureMode = cameraValue.exposureMode;
1200
+ final bool isLocked = exposureMode == ExposureMode .locked;
1201
+ return Column (
1202
+ children: < Widget > [
1203
+ ValueListenableBuilder <bool >(
1204
+ valueListenable: _isExposureModeDisplays,
1205
+ builder: (_, bool value, Widget ? child) => AnimatedOpacity (
1206
+ duration: _kDuration,
1207
+ opacity: value ? 1 : 0 ,
1208
+ child: child,
1209
+ ),
1210
+ child: GestureDetector (
1211
+ onTap: switchExposureMode,
1212
+ child: SizedBox .fromSize (
1213
+ size: Size .square (size),
1214
+ child: Icon (
1215
+ isLocked ? Icons .lock_rounded : Icons .lock_open_rounded,
1216
+ size: size,
1217
+ color: isLocked ? _lockedColor : null ,
1214
1218
),
1215
1219
),
1216
- const SizedBox (height : verticalGap ),
1217
- Expanded (
1218
- child : _exposureSlider (mode, size, height, verticalGap),
1219
- ),
1220
- const SizedBox ( height: verticalGap),
1221
- SizedBox . fromSize (size : Size . square (size) ),
1222
- ] ,
1223
- );
1224
- } ,
1220
+ ),
1221
+ ),
1222
+ const SizedBox ( height: verticalGap),
1223
+ Expanded (
1224
+ child : _exposureSlider (exposureMode, size, height, verticalGap),
1225
+ ),
1226
+ const SizedBox (height : verticalGap) ,
1227
+ SizedBox . fromSize (size : Size . square (size)),
1228
+ ] ,
1225
1229
);
1226
1230
}
1227
1231
@@ -1450,7 +1454,9 @@ class CameraPickerState extends State<CameraPicker>
1450
1454
if (enableSetExposure)
1451
1455
_exposureDetectorWidget (c, constraints),
1452
1456
_initializeWrapper (
1453
- builder: (_, __) => _focusingAreaWidget (constraints),
1457
+ builder: (CameraValue cameraValue, Widget ? w) {
1458
+ return _focusingAreaWidget (cameraValue, constraints);
1459
+ },
1454
1460
),
1455
1461
_contentBuilder (constraints),
1456
1462
if (config.foregroundBuilder != null )
0 commit comments