Navaron Bracke

return instead of throw when toggling torch on Android

... ... @@ -376,7 +376,7 @@ class MobileScanner(
*/
fun toggleTorch(enableTorch: Boolean) {
if (camera == null) {
throw TorchWhenStopped()
return
}
if (camera?.cameraInfo?.hasFlashUnit() == true) {
... ...
... ... @@ -4,6 +4,5 @@ class NoCamera : Exception()
class AlreadyStarted : Exception()
class AlreadyStopped : Exception()
class CameraError : Exception()
class TorchWhenStopped : Exception()
class ZoomWhenStopped : Exception()
class ZoomNotInRange : Exception()
\ No newline at end of file
... ...
... ... @@ -237,12 +237,8 @@ class MobileScannerHandler(
}
private fun toggleTorch(call: MethodCall, result: MethodChannel.Result) {
try {
mobileScanner!!.toggleTorch(call.arguments == 1)
result.success(null)
} catch (e: TorchWhenStopped) {
result.error("MobileScanner", "Called toggleTorch() while stopped!", null)
}
mobileScanner!!.toggleTorch(call.arguments == 1)
result.success(null)
}
private fun setScale(call: MethodCall, result: MethodChannel.Result) {
... ...
... ... @@ -277,7 +277,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
// Turn on the torch if requested.
if (torch) {
do {
toggleTorchInternal(.on)
self.toggleTorchInternal(.on)
} catch {
result(FlutterError(code: error.localizedDescription, message: nil, details: nil))
return
... ... @@ -335,7 +335,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
let requestedTorchMode: AVCaptureDevice.TorchMode = call.arguments as! Int == 1 ? .on : .off
do {
try toggleTorchInternal(requestedTorchMode)
try self.toggleTorchInternal(requestedTorchMode)
result(nil)
} catch {
result(FlutterError(code: error.localizedDescription, message: nil, details: nil))
... ...