Showing
4 changed files
with
8 additions
and
43 deletions
| @@ -11,8 +11,7 @@ export 'src/enums/phone_type.dart'; | @@ -11,8 +11,7 @@ export 'src/enums/phone_type.dart'; | ||
| 11 | export 'src/enums/torch_state.dart'; | 11 | export 'src/enums/torch_state.dart'; |
| 12 | export 'src/mobile_scanner.dart'; | 12 | export 'src/mobile_scanner.dart'; |
| 13 | export 'src/mobile_scanner_controller.dart'; | 13 | export 'src/mobile_scanner_controller.dart'; |
| 14 | -export 'src/mobile_scanner_exception.dart' | ||
| 15 | - hide PermissionRequestPendingException; | 14 | +export 'src/mobile_scanner_exception.dart'; |
| 16 | export 'src/mobile_scanner_platform_interface.dart'; | 15 | export 'src/mobile_scanner_platform_interface.dart'; |
| 17 | export 'src/objects/address.dart'; | 16 | export 'src/objects/address.dart'; |
| 18 | export 'src/objects/barcode.dart'; | 17 | export 'src/objects/barcode.dart'; |
| @@ -246,13 +246,6 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | @@ -246,13 +246,6 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | ||
| 246 | ); | 246 | ); |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | - // Permission was denied, do nothing. | ||
| 250 | - // When the controller is stopped, | ||
| 251 | - // the error is reset so the permission can be requested again if possible. | ||
| 252 | - if (value.error?.errorCode == MobileScannerErrorCode.permissionDenied) { | ||
| 253 | - return; | ||
| 254 | - } | ||
| 255 | - | ||
| 256 | // Do nothing if the camera is already running. | 249 | // Do nothing if the camera is already running. |
| 257 | if (value.isRunning) { | 250 | if (value.isRunning) { |
| 258 | return; | 251 | return; |
| @@ -306,8 +299,6 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | @@ -306,8 +299,6 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | ||
| 306 | zoomScale: 1.0, | 299 | zoomScale: 1.0, |
| 307 | ); | 300 | ); |
| 308 | } | 301 | } |
| 309 | - } on PermissionRequestPendingException catch (_) { | ||
| 310 | - // If a permission request was already pending, do nothing. | ||
| 311 | } | 302 | } |
| 312 | } | 303 | } |
| 313 | 304 |
| @@ -40,13 +40,6 @@ class MobileScannerErrorDetails { | @@ -40,13 +40,6 @@ class MobileScannerErrorDetails { | ||
| 40 | final String? message; | 40 | final String? message; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | -/// This class represents an exception that is thrown | ||
| 44 | -/// when the scanner was (re)started while a permission request was pending. | ||
| 45 | -/// | ||
| 46 | -/// This exception type is only used internally, | ||
| 47 | -/// and is not part of the public API. | ||
| 48 | -class PermissionRequestPendingException implements Exception {} | ||
| 49 | - | ||
| 50 | /// This class represents an exception thrown by the [MobileScannerController] | 43 | /// This class represents an exception thrown by the [MobileScannerController] |
| 51 | /// when a barcode scanning error occurs when processing an input frame. | 44 | /// when a barcode scanning error occurs when processing an input frame. |
| 52 | class MobileScannerBarcodeException implements Exception { | 45 | class MobileScannerBarcodeException implements Exception { |
| @@ -39,12 +39,6 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -39,12 +39,6 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 39 | /// The container div element for the camera view. | 39 | /// The container div element for the camera view. |
| 40 | late HTMLDivElement _divElement; | 40 | late HTMLDivElement _divElement; |
| 41 | 41 | ||
| 42 | - /// The flag that keeps track of whether a permission request is in progress. | ||
| 43 | - /// | ||
| 44 | - /// On the web, a permission request triggers a dialog, that in turn triggers a lifecycle change. | ||
| 45 | - /// While the permission request is in progress, any attempts at (re)starting the camera should be ignored. | ||
| 46 | - bool _permissionRequestInProgress = false; | ||
| 47 | - | ||
| 48 | /// The stream controller for the media track settings stream. | 42 | /// The stream controller for the media track settings stream. |
| 49 | /// | 43 | /// |
| 50 | /// Currently, only the facing mode setting can be supported, | 44 | /// Currently, only the facing mode setting can be supported, |
| @@ -199,17 +193,12 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -199,17 +193,12 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 199 | } | 193 | } |
| 200 | 194 | ||
| 201 | try { | 195 | try { |
| 202 | - _permissionRequestInProgress = true; | ||
| 203 | - | ||
| 204 | // Retrieving the media devices requests the camera permission. | 196 | // Retrieving the media devices requests the camera permission. |
| 205 | final MediaStream videoStream = | 197 | final MediaStream videoStream = |
| 206 | await window.navigator.mediaDevices.getUserMedia(constraints).toDart; | 198 | await window.navigator.mediaDevices.getUserMedia(constraints).toDart; |
| 207 | 199 | ||
| 208 | - _permissionRequestInProgress = false; | ||
| 209 | - | ||
| 210 | return videoStream; | 200 | return videoStream; |
| 211 | } on DOMException catch (error, stackTrace) { | 201 | } on DOMException catch (error, stackTrace) { |
| 212 | - _permissionRequestInProgress = false; | ||
| 213 | final String errorMessage = error.toString(); | 202 | final String errorMessage = error.toString(); |
| 214 | 203 | ||
| 215 | MobileScannerErrorCode errorCode = MobileScannerErrorCode.genericError; | 204 | MobileScannerErrorCode errorCode = MobileScannerErrorCode.genericError; |
| @@ -272,20 +261,7 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -272,20 +261,7 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 272 | 261 | ||
| 273 | @override | 262 | @override |
| 274 | Future<MobileScannerViewAttributes> start(StartOptions startOptions) async { | 263 | Future<MobileScannerViewAttributes> start(StartOptions startOptions) async { |
| 275 | - // If the permission request has not yet completed, | ||
| 276 | - // the camera view is not ready yet. | ||
| 277 | - // Prevent the permission popup from triggering a restart of the scanner. | ||
| 278 | - if (_permissionRequestInProgress) { | ||
| 279 | - throw PermissionRequestPendingException(); | ||
| 280 | - } | ||
| 281 | - | ||
| 282 | - _barcodeReader = ZXingBarcodeReader(); | ||
| 283 | - | ||
| 284 | - await _barcodeReader?.maybeLoadLibrary( | ||
| 285 | - alternateScriptUrl: _alternateScriptUrl, | ||
| 286 | - ); | ||
| 287 | - | ||
| 288 | - if (_barcodeReader?.isScanning ?? false) { | 264 | + if (_barcodeReader != null) { |
| 289 | throw const MobileScannerException( | 265 | throw const MobileScannerException( |
| 290 | errorCode: MobileScannerErrorCode.controllerAlreadyInitialized, | 266 | errorCode: MobileScannerErrorCode.controllerAlreadyInitialized, |
| 291 | errorDetails: MobileScannerErrorDetails( | 267 | errorDetails: MobileScannerErrorDetails( |
| @@ -295,6 +271,12 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -295,6 +271,12 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 295 | ); | 271 | ); |
| 296 | } | 272 | } |
| 297 | 273 | ||
| 274 | + _barcodeReader = ZXingBarcodeReader(); | ||
| 275 | + | ||
| 276 | + await _barcodeReader?.maybeLoadLibrary( | ||
| 277 | + alternateScriptUrl: _alternateScriptUrl, | ||
| 278 | + ); | ||
| 279 | + | ||
| 298 | // Request camera permissions and prepare the video stream. | 280 | // Request camera permissions and prepare the video stream. |
| 299 | final MediaStream videoStream = await _prepareVideoStream( | 281 | final MediaStream videoStream = await _prepareVideoStream( |
| 300 | startOptions.cameraDirection, | 282 | startOptions.cameraDirection, |
-
Please register or login to post a comment