Skip to content

Commit dd11736

Browse files
authored
🐛 Handle exceptions after all flows (#216)
1 parent 9bcd0ed commit dd11736

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ that can be found in the LICENSE file. -->
66

77
See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions.
88

9+
## 4.0.4
10+
11+
### Fixes
12+
13+
- Handle exceptions after all flows.
14+
915
## 4.0.3
1016

1117
### Fixes

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: wechat_camera_picker_demo
22
description: A new Flutter project.
3-
version: 4.0.3+28
3+
version: 4.0.4+29
44
publish_to: none
55

66
environment:

lib/src/states/camera_picker_state.dart

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ class CameraPickerState extends State<CameraPicker>
343343
StackTrace.current,
344344
pickerConfig.onError,
345345
);
346+
return;
346347
}
347348

348349
initFlashModesForCameras();
@@ -622,9 +623,10 @@ class CameraPickerState extends State<CameraPicker>
622623
await controller.setExposureMode(newMode);
623624
} catch (e, s) {
624625
handleErrorWithHandler(e, s, pickerConfig.onError);
626+
} finally {
627+
restartExposureModeDisplayTimer();
628+
restartExposureFadeOutTimer();
625629
}
626-
restartExposureModeDisplayTimer();
627-
restartExposureFadeOutTimer();
628630
}
629631

630632
/// Use the [position] to set exposure and focus.
@@ -714,17 +716,18 @@ class CameraPickerState extends State<CameraPicker>
714716
),
715717
);
716718
} catch (e, s) {
717-
handleErrorWithHandler(e, s, pickerConfig.onError);
718719
hasError = true;
719720
currentExposureSliderOffset.value = previousSliderOffsetValue;
720721
currentExposureOffset.value = previousOffsetValue;
722+
handleErrorWithHandler(e, s, pickerConfig.onError);
723+
} finally {
724+
if (!hasError && !isFocusPointDisplays.value) {
725+
isFocusPointDisplays.value = true;
726+
}
727+
restartExposurePointDisplayTimer();
728+
restartExposureModeDisplayTimer();
729+
restartExposureFadeOutTimer();
721730
}
722-
if (!hasError && !isFocusPointDisplays.value) {
723-
isFocusPointDisplays.value = true;
724-
}
725-
restartExposurePointDisplayTimer();
726-
restartExposureModeDisplayTimer();
727-
restartExposureFadeOutTimer();
728731
}
729732

730733
/// Request to set the focus and the exposure point on the [localPosition],
@@ -897,8 +900,9 @@ class CameraPickerState extends State<CameraPicker>
897900
recordCountdownTimer?.cancel();
898901
isShootingButtonAnimate = false;
899902
handleErrorWithHandler(e, s, pickerConfig.onError);
903+
} finally {
904+
recordStopwatch.stop();
900905
}
901-
recordStopwatch.stop();
902906
} finally {
903907
safeSetState(() {});
904908
}
@@ -945,9 +949,9 @@ class CameraPickerState extends State<CameraPicker>
945949
await controller.resumePreview();
946950
}
947951
} catch (e, s) {
948-
handleErrorWithHandler(e, s, pickerConfig.onError);
949952
handleError();
950953
initCameras();
954+
handleErrorWithHandler(e, s, pickerConfig.onError);
951955
} finally {
952956
isControllerBusy = false;
953957
safeSetState(() {});

lib/src/states/camera_picker_viewer_state.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import '../constants/constants.dart';
1515
import '../constants/enums.dart';
1616
import '../constants/styles.dart';
1717
import '../constants/type_defs.dart';
18+
import '../internals/extensions.dart';
1819
import '../internals/methods.dart';
1920
import '../widgets/camera_picker.dart';
2021
import '../widgets/camera_picker_viewer.dart';
@@ -83,9 +84,7 @@ class CameraPickerViewerState extends State<CameraPickerViewer> {
8384
realDebugPrint('Error when initializing video controller: $e');
8485
handleErrorWithHandler(e, s, onError);
8586
} finally {
86-
if (mounted) {
87-
setState(() {});
88-
}
87+
safeSetState(() {});
8988
}
9089
}
9190

@@ -141,12 +140,11 @@ class CameraPickerViewerState extends State<CameraPickerViewer> {
141140
);
142141
} catch (e, s) {
143142
handleErrorWithHandler(e, s, onError);
143+
} finally {
144+
safeSetState(() {
145+
isSavingEntity = false;
146+
});
144147
}
145-
isSavingEntity = false;
146-
if (mounted) {
147-
setState(() {});
148-
}
149-
return;
150148
}
151149
AssetEntity? entity;
152150
try {
@@ -184,7 +182,9 @@ class CameraPickerViewerState extends State<CameraPickerViewer> {
184182
realDebugPrint('Saving entity failed: $e');
185183
handleErrorWithHandler(e, s, onError);
186184
} finally {
187-
isSavingEntity = false;
185+
safeSetState(() {
186+
isSavingEntity = false;
187+
});
188188
if (mounted) {
189189
Navigator.of(context).pop(entity);
190190
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: wechat_camera_picker
2-
version: 4.0.3
2+
version: 4.0.4
33
description: |
44
A camera picker for Flutter projects based on WeChat's UI,
55
which is also a separate runnable extension to the

0 commit comments

Comments
 (0)