diff --git a/CHANGELOG.md b/CHANGELOG.md index 9742981..d54cce2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ that can be found in the LICENSE file. --> See the [Migration Guide](guides/migration_guide.md) for breaking changes between versions. +## 4.2.0-dev.3 + +### Improvements + +- Roll `sensors_plus`. +- Catch exceptions when obtain/subscribe to the accelerometer stream. + ## 4.2.0-dev.2 ### Breaking changes diff --git a/lib/src/states/camera_picker_state.dart b/lib/src/states/camera_picker_state.dart index 149f815..27ab990 100644 --- a/lib/src/states/camera_picker_state.dart +++ b/lib/src/states/camera_picker_state.dart @@ -216,7 +216,7 @@ class CameraPickerState extends State bool retriedAfterInvalidInitialize = false; /// Subscribe to the accelerometer. - late final StreamSubscription accelerometerSubscription; + StreamSubscription? accelerometerSubscription; /// The locked capture orientation of the current camera instance. DeviceOrientation? lockedCaptureOrientation; @@ -228,9 +228,7 @@ class CameraPickerState extends State Constants.textDelegate = widget.pickerConfig.textDelegate ?? cameraPickerTextDelegateFromLocale(widget.locale); initCameras(); - accelerometerSubscription = accelerometerEvents.listen( - handleAccelerometerEvent, - ); + initAccelerometerSubscription(); } @override @@ -249,7 +247,7 @@ class CameraPickerState extends State exposureFadeOutTimer?.cancel(); recordDetectTimer?.cancel(); recordCountdownTimer?.cancel(); - accelerometerSubscription.cancel(); + accelerometerSubscription?.cancel(); super.dispose(); } @@ -491,6 +489,20 @@ class CameraPickerState extends State }); } + /// Starts to listen on accelerometer events. + void initAccelerometerSubscription() { + try { + final stream = accelerometerEventStream(); + accelerometerSubscription = stream.listen(handleAccelerometerEvent); + } catch (e, s) { + realDebugPrint( + 'The device does not seem to support accelerometer. ' + 'The captured files orientation might be incorrect.', + ); + handleErrorWithHandler(e, s, pickerConfig.onError); + } + } + /// Lock capture orientation according to the current status of the device, /// which enables the captured file stored the correct orientation. void handleAccelerometerEvent(AccelerometerEvent event) { diff --git a/pubspec.yaml b/pubspec.yaml index 20a563b..ca06b60 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: wechat_camera_picker -version: 4.2.0-dev.2 +version: 4.2.0-dev.3 description: | A camera picker for Flutter projects based on WeChat's UI, which is also a separate runnable extension to the @@ -27,7 +27,7 @@ dependencies: path: ^1.8.0 photo_manager: ^3.0.0-dev.1 photo_manager_image_provider: ^2.0.0 - sensors_plus: ^3.1.0 + sensors_plus: ^4.0.1 video_player: ^2.7.0 dev_dependencies: