Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Handle exceptions after all flows #216

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Comment on lines -145 to -149

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! This is a very bad change... The "return" is omitted @AlexV525 . So the issue about duplicate saving entity has happened again.

}
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
Loading