only let the torch state callback event update the torch state
Showing
1 changed file
with
5 additions
and
7 deletions
| @@ -282,9 +282,6 @@ class MobileScannerController { | @@ -282,9 +282,6 @@ class MobileScannerController { | ||
| 282 | 282 | ||
| 283 | final hasTorch = startResult['torchable'] as bool? ?? false; | 283 | final hasTorch = startResult['torchable'] as bool? ?? false; |
| 284 | hasTorchState.value = hasTorch; | 284 | hasTorchState.value = hasTorch; |
| 285 | - if (hasTorch && torchEnabled) { | ||
| 286 | - torchState.value = TorchState.on; | ||
| 287 | - } | ||
| 288 | 285 | ||
| 289 | final Size size; | 286 | final Size size; |
| 290 | 287 | ||
| @@ -333,14 +330,15 @@ class MobileScannerController { | @@ -333,14 +330,15 @@ class MobileScannerController { | ||
| 333 | throw const MobileScannerException( | 330 | throw const MobileScannerException( |
| 334 | errorCode: MobileScannerErrorCode.controllerUninitialized, | 331 | errorCode: MobileScannerErrorCode.controllerUninitialized, |
| 335 | ); | 332 | ); |
| 336 | - } else if (!hasTorch) { | 333 | + } |
| 334 | + | ||
| 335 | + if (!hasTorch) { | ||
| 337 | return; | 336 | return; |
| 338 | } | 337 | } |
| 339 | 338 | ||
| 340 | - torchState.value = | ||
| 341 | - torchState.value == TorchState.off ? TorchState.on : TorchState.off; | 339 | + final TorchState newState = torchState.value == TorchState.off ? TorchState.on : TorchState.off; |
| 342 | 340 | ||
| 343 | - await _methodChannel.invokeMethod('torch', torchState.value.rawValue); | 341 | + await _methodChannel.invokeMethod('torch', newState.rawValue); |
| 344 | } | 342 | } |
| 345 | 343 | ||
| 346 | /// Changes the state of the camera (front or back). | 344 | /// Changes the state of the camera (front or back). |
-
Please register or login to post a comment