Skip to content

Commit

Permalink
🐛 Handle exceptions after all flows (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Oct 28, 2023
1 parent 9bcd0ed commit dd11736
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ that can be found in the LICENSE file. -->

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

## 4.0.4

### Fixes

- Handle exceptions after all flows.

## 4.0.3

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: wechat_camera_picker_demo
description: A new Flutter project.
version: 4.0.3+28
version: 4.0.4+29
publish_to: none

environment:
Expand Down
26 changes: 15 additions & 11 deletions lib/src/states/camera_picker_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ class CameraPickerState extends State<CameraPicker>
StackTrace.current,
pickerConfig.onError,
);
return;
}

initFlashModesForCameras();
Expand Down Expand Up @@ -622,9 +623,10 @@ class CameraPickerState extends State<CameraPicker>
await controller.setExposureMode(newMode);
} catch (e, s) {
handleErrorWithHandler(e, s, pickerConfig.onError);
} finally {
restartExposureModeDisplayTimer();
restartExposureFadeOutTimer();
}
restartExposureModeDisplayTimer();
restartExposureFadeOutTimer();
}

/// Use the [position] to set exposure and focus.
Expand Down Expand Up @@ -714,17 +716,18 @@ class CameraPickerState extends State<CameraPicker>
),
);
} catch (e, s) {
handleErrorWithHandler(e, s, pickerConfig.onError);
hasError = true;
currentExposureSliderOffset.value = previousSliderOffsetValue;
currentExposureOffset.value = previousOffsetValue;
handleErrorWithHandler(e, s, pickerConfig.onError);
} finally {
if (!hasError && !isFocusPointDisplays.value) {
isFocusPointDisplays.value = true;
}
restartExposurePointDisplayTimer();
restartExposureModeDisplayTimer();
restartExposureFadeOutTimer();
}
if (!hasError && !isFocusPointDisplays.value) {
isFocusPointDisplays.value = true;
}
restartExposurePointDisplayTimer();
restartExposureModeDisplayTimer();
restartExposureFadeOutTimer();
}

/// Request to set the focus and the exposure point on the [localPosition],
Expand Down Expand Up @@ -897,8 +900,9 @@ class CameraPickerState extends State<CameraPicker>
recordCountdownTimer?.cancel();
isShootingButtonAnimate = false;
handleErrorWithHandler(e, s, pickerConfig.onError);
} finally {
recordStopwatch.stop();
}
recordStopwatch.stop();
} finally {
safeSetState(() {});
}
Expand Down Expand Up @@ -945,9 +949,9 @@ class CameraPickerState extends State<CameraPicker>
await controller.resumePreview();
}
} catch (e, s) {
handleErrorWithHandler(e, s, pickerConfig.onError);
handleError();
initCameras();
handleErrorWithHandler(e, s, pickerConfig.onError);
} finally {
isControllerBusy = false;
safeSetState(() {});
Expand Down
18 changes: 9 additions & 9 deletions lib/src/states/camera_picker_viewer_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import '../constants/constants.dart';
import '../constants/enums.dart';
import '../constants/styles.dart';
import '../constants/type_defs.dart';
import '../internals/extensions.dart';
import '../internals/methods.dart';
import '../widgets/camera_picker.dart';
import '../widgets/camera_picker_viewer.dart';
Expand Down Expand Up @@ -83,9 +84,7 @@ class CameraPickerViewerState extends State<CameraPickerViewer> {
realDebugPrint('Error when initializing video controller: $e');
handleErrorWithHandler(e, s, onError);
} finally {
if (mounted) {
setState(() {});
}
safeSetState(() {});
}
}

Expand Down Expand Up @@ -141,12 +140,11 @@ class CameraPickerViewerState extends State<CameraPickerViewer> {
);
} catch (e, s) {
handleErrorWithHandler(e, s, onError);
} finally {
safeSetState(() {
isSavingEntity = false;
});
}
isSavingEntity = false;
if (mounted) {
setState(() {});
}
return;
}
AssetEntity? entity;
try {
Expand Down Expand Up @@ -184,7 +182,9 @@ class CameraPickerViewerState extends State<CameraPickerViewer> {
realDebugPrint('Saving entity failed: $e');
handleErrorWithHandler(e, s, onError);
} finally {
isSavingEntity = false;
safeSetState(() {
isSavingEntity = false;
});
if (mounted) {
Navigator.of(context).pop(entity);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: wechat_camera_picker
version: 4.0.3
version: 4.0.4
description: |
A camera picker for Flutter projects based on WeChat's UI,
which is also a separate runnable extension to the
Expand Down

0 comments on commit dd11736

Please sign in to comment.