Navaron Bracke
Committed by GitHub

Merge pull request #1036 from EArminjon/bug/widget-disposed-during-start

fix: widget-disposed-during-start
  1 +## 5.0.2
  2 +
  3 +Bugs fixed:
  4 +* 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 +
1 ## 5.0.1 6 ## 5.0.1
2 7
3 Improvements: 8 Improvements:
@@ -274,16 +274,18 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -274,16 +274,18 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
274 options, 274 options,
275 ); 275 );
276 276
277 - value = value.copyWith(  
278 - availableCameras: viewAttributes.numberOfCameras,  
279 - cameraDirection: effectiveDirection,  
280 - isInitialized: true,  
281 - isRunning: true,  
282 - size: viewAttributes.size,  
283 - // If the device has a flashlight, let the platform update the torch state.  
284 - // If it does not have one, provide the unavailable state directly.  
285 - torchState: viewAttributes.hasTorch ? null : TorchState.unavailable,  
286 - ); 277 + if (!_isDisposed) {
  278 + value = value.copyWith(
  279 + availableCameras: viewAttributes.numberOfCameras,
  280 + cameraDirection: effectiveDirection,
  281 + isInitialized: true,
  282 + isRunning: true,
  283 + size: viewAttributes.size,
  284 + // If the device has a flashlight, let the platform update the torch state.
  285 + // If it does not have one, provide the unavailable state directly.
  286 + torchState: viewAttributes.hasTorch ? null : TorchState.unavailable,
  287 + );
  288 + }
287 } on MobileScannerException catch (error) { 289 } on MobileScannerException catch (error) {
288 // The initialization finished with an error. 290 // The initialization finished with an error.
289 // To avoid stale values, reset the output size, 291 // To avoid stale values, reset the output size,
1 name: mobile_scanner 1 name: mobile_scanner
2 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. 2 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.
3 -version: 5.0.1 3 +version: 5.0.2
4 repository: https://github.com/juliansteenbakker/mobile_scanner 4 repository: https://github.com/juliansteenbakker/mobile_scanner
5 5
6 screenshots: 6 screenshots:
@@ -24,7 +24,7 @@ dependencies: @@ -24,7 +24,7 @@ dependencies:
24 sdk: flutter 24 sdk: flutter
25 flutter_web_plugins: 25 flutter_web_plugins:
26 sdk: flutter 26 sdk: flutter
27 - plugin_platform_interface: ^2.0.2 27 + plugin_platform_interface: ^2.0.2
28 web: ^0.5.1 28 web: ^0.5.1
29 29
30 dev_dependencies: 30 dev_dependencies: