From 30bbeebde64445a8297946fc19846e0dae7ebf19 Mon Sep 17 00:00:00 2001 From: Enguerrand_ARMINJON_MAC_2 Date: Tue, 23 Apr 2024 19:22:18 +0200 Subject: [PATCH 1/2] bug/widget-disposed-during-start --- CHANGELOG.md | 5 +++++ lib/src/mobile_scanner_controller.dart | 22 ++++++++++++---------- pubspec.yaml | 4 ++-- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 728306c62..243a63d26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 5.0.2 + +Bugs fixed: +* Catch an exception that could appear if MobileScannerController is disposed during start(). [#1036](https://github.com/juliansteenbakker/mobile_scanner/pull/1036) (thanks @EArminjon !) + ## 5.0.1 Improvements: diff --git a/lib/src/mobile_scanner_controller.dart b/lib/src/mobile_scanner_controller.dart index bfa221d3f..5793a2476 100644 --- a/lib/src/mobile_scanner_controller.dart +++ b/lib/src/mobile_scanner_controller.dart @@ -274,16 +274,18 @@ class MobileScannerController extends ValueNotifier { options, ); - value = value.copyWith( - availableCameras: viewAttributes.numberOfCameras, - cameraDirection: effectiveDirection, - isInitialized: true, - isRunning: true, - size: viewAttributes.size, - // If the device has a flashlight, let the platform update the torch state. - // If it does not have one, provide the unavailable state directly. - torchState: viewAttributes.hasTorch ? null : TorchState.unavailable, - ); + if (!_isDisposed) { + value = value.copyWith( + availableCameras: viewAttributes.numberOfCameras, + cameraDirection: effectiveDirection, + isInitialized: true, + isRunning: true, + size: viewAttributes.size, + // If the device has a flashlight, let the platform update the torch state. + // If it does not have one, provide the unavailable state directly. + torchState: viewAttributes.hasTorch ? null : TorchState.unavailable, + ); + } } on MobileScannerException catch (error) { // The initialization finished with an error. // To avoid stale values, reset the output size, diff --git a/pubspec.yaml b/pubspec.yaml index 70f7d8119..2f2cad484 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mobile_scanner description: A universal barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS. -version: 5.0.1 +version: 5.0.2 repository: https://github.com/juliansteenbakker/mobile_scanner screenshots: @@ -24,7 +24,7 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - plugin_platform_interface: ^2.0.2 + plugin_platform_interface: ^2.0.2 web: ^0.5.1 dev_dependencies: From 2548f3b480e2026161ef8cac25824f4b8378ce87 Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Tue, 30 Apr 2024 11:36:15 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 243a63d26..10f36b77b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## 5.0.2 Bugs fixed: -* Catch an exception that could appear if MobileScannerController is disposed during start(). [#1036](https://github.com/juliansteenbakker/mobile_scanner/pull/1036) (thanks @EArminjon !) +* Fixed a crash when the controller is disposed while it is still starting. [#1036](https://github.com/juliansteenbakker/mobile_scanner/pull/1036) (thanks @EArminjon !) ## 5.0.1