Julian Steenbakker
Committed by GitHub

Merge pull request #400 from juliansteenbakker/imp/error-handling

imp: error handling
@@ -15,16 +15,22 @@ Breaking changes: @@ -15,16 +15,22 @@ Breaking changes:
15 15
16 Improvements: 16 Improvements:
17 * Toggling the device torch now does nothing if the device has no torch, rather than throwing an error. 17 * Toggling the device torch now does nothing if the device has no torch, rather than throwing an error.
  18 +* Removed `called stop while already stopped` messages.
18 19
19 Features: 20 Features:
20 * Added a new `placeholderBuilder` function to the `MobileScanner` widget to customize the preview placeholder. 21 * Added a new `placeholderBuilder` function to the `MobileScanner` widget to customize the preview placeholder.
21 * Added `autoStart` parameter to MobileScannerController(). If set to false, controller won't start automatically. 22 * Added `autoStart` parameter to MobileScannerController(). If set to false, controller won't start automatically.
22 -  
23 -Fixed:  
24 -* Fixed a memory leak where the `MobileScanner` widget would never close its subscription to the barcode events.  
25 -* Fixed a dependency on all properties of `MediaQueryData` to build the preview widget. Now the preview only depends on its layout constraints. 23 +* Added `hasTorch` function on MobileScannerController(). After starting the controller, you can check if the device has a torch.
  24 +
  25 +Fixes:
  26 +* Fixes the missing gradle setup for the Android project, which prevented gradle sync from working.
  27 +* Fixes `MobileScannerController.stop()` throwing when already stopped.
  28 +* Fixes `MobileScannerController.toggleTorch()` throwing if the device has no torch.
  29 + Now it does nothing if the torch is not available.
  30 +* Fixes a memory leak where the `MobileScanner` would keep listening to the barcode events.
  31 +* Fixes the `MobileScanner` preview depending on all attributes of `MediaQueryData`.
  32 + Now it only depends on its layout constraints.
26 * Fixed a potential crash when the scanner is restarted due to the app being resumed. 33 * Fixed a potential crash when the scanner is restarted due to the app being resumed.
27 -* Various documentation improvements.  
28 34
29 ## 3.0.0-beta.2 35 ## 3.0.0-beta.2
30 Breaking changes: 36 Breaking changes:
@@ -101,6 +101,19 @@ class MobileScannerController { @@ -101,6 +101,19 @@ class MobileScannerController {
101 101
102 bool? _hasTorch; 102 bool? _hasTorch;
103 103
  104 + /// Returns whether the device has a torch.
  105 + ///
  106 + /// Throws an error if the controller is not initialized.
  107 + bool get hasTorch {
  108 + if (_hasTorch == null) {
  109 + throw const MobileScannerException(
  110 + errorCode: MobileScannerErrorCode.controllerUninitialized,
  111 + );
  112 + }
  113 +
  114 + return _hasTorch!;
  115 + }
  116 +
104 /// Set the starting arguments for the camera 117 /// Set the starting arguments for the camera
105 Map<String, dynamic> _argumentsToMap({CameraFacing? cameraFacingOverride}) { 118 Map<String, dynamic> _argumentsToMap({CameraFacing? cameraFacingOverride}) {
106 final Map<String, dynamic> arguments = {}; 119 final Map<String, dynamic> arguments = {};
@@ -238,9 +238,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, @@ -238,9 +238,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
238 238
239 func toggleTorch(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { 239 func toggleTorch(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
240 if (device == nil) { 240 if (device == nil) {
241 - result(FlutterError(code: "MobileScanner",  
242 - message: "Called toggleTorch() while stopped!",  
243 - details: nil)) 241 + result(nil)
244 return 242 return
245 } 243 }
246 do { 244 do {