diff --git a/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt b/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt index 251cc6e..c7355b3 100644 --- a/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt +++ b/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt @@ -41,13 +41,13 @@ class QRView(messenger: BinaryMessenger, id: Int, private val params: HashMap?, grantResults: IntArray): Boolean { - if (requestCode == Shared.CAMERA_REQUEST_ID && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + if (requestCode == Shared.CAMERA_REQUEST_ID && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { permissionGranted = true channel.invokeMethod("onPermissionSet", true) return true diff --git a/lib/src/qr_code_scanner.dart b/lib/src/qr_code_scanner.dart index 4fd9af8..0e4fb8d 100644 --- a/lib/src/qr_code_scanner.dart +++ b/lib/src/qr_code_scanner.dart @@ -64,12 +64,12 @@ class _QRViewState extends State { super.initState(); WidgetsBinding.instance.addObserver(LifecycleEventHandler( resumeCallBack: () async => { - if (_channel != null) { - QRViewController.updateDimensions( - widget.key, _channel, - overlay: widget.overlay) - } - })); + if (_channel != null) + { + QRViewController.updateDimensions(widget.key, _channel, + overlay: widget.overlay) + } + })); } @override @@ -86,9 +86,9 @@ class _QRViewState extends State { bool onNotification(notification) { Future.microtask(() => { - QRViewController.updateDimensions(widget.key, _channel, - overlay: widget.overlay) - }); + QRViewController.updateDimensions(widget.key, _channel, + overlay: widget.overlay) + }); return false; } @@ -139,9 +139,9 @@ class _QRViewState extends State { _channel = MethodChannel('net.touchcapture.qr.flutterqr/qrview_$id'); // Start scan after creation of the view - final controller = - QRViewController._(_channel, widget.key, widget.onPermissionSet, widget.cameraFacing) - .._startScan(widget.key, widget.overlay, widget.formatsAllowed); + final controller = QRViewController._( + _channel, widget.key, widget.onPermissionSet, widget.cameraFacing) + .._startScan(widget.key, widget.overlay, widget.formatsAllowed); // Initialize the controller for controlling the QRView if (widget.onQRViewCreated != null) { @@ -167,7 +167,8 @@ class _QrCameraSettings { class QRViewController { QRViewController._(MethodChannel channel, GlobalKey qrKey, PermissionSetCallback onPermissionSet, CameraFacing cameraFacing) - : _channel = channel, _cameraFacing = cameraFacing{ + : _channel = channel, + _cameraFacing = cameraFacing { _channel.setMethodCallHandler((call) async { switch (call.method) { case 'onRecognizeQR': @@ -323,7 +324,7 @@ class QRViewController { await Future.delayed(Duration(milliseconds: 300)); } final RenderBox renderBox = key.currentContext.findRenderObject(); - try { + try { await channel.invokeMethod('setDimensions', { 'width': renderBox.size.width, 'height': renderBox.size.height,