From 4192eb0b2c65ea5890da5ac654c96b80afed65b1 Mon Sep 17 00:00:00 2001 From: jawa0919 Date: Fri, 25 Jun 2021 18:03:07 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20feat(Permission):=20add=20alert?= =?UTF-8?q?=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/main.dart | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 8e7054e..abf6ed0 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,10 +1,32 @@ +import 'dart:developer'; import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:qr_code_scanner/qr_code_scanner.dart'; -void main() => runApp(MaterialApp(home: QRViewExample())); +void main() => runApp(MaterialApp(home: MyHome())); + +class MyHome extends StatelessWidget { + const MyHome({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: Text('Flutter Demo Home Page')), + body: Center( + child: ElevatedButton( + onPressed: () { + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => QRViewExample(), + )); + }, + child: Text('qrView'), + ), + ), + ); + } +} class QRViewExample extends StatefulWidget { @override @@ -134,6 +156,7 @@ class _QRViewExampleState extends State { borderLength: 30, borderWidth: 10, cutOutSize: scanArea), + onPermissionSet: (ctrl, p) => _onPermissionSet(context, ctrl, p), ); } @@ -148,6 +171,15 @@ class _QRViewExampleState extends State { }); } + void _onPermissionSet(BuildContext context, QRViewController ctrl, bool p) { + log('${DateTime.now().toIso8601String()}_onPermissionSet $p'); + if (!p) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('no Permission')), + ); + } + } + @override void dispose() { controller?.dispose(); From 97b19860f31fecc58434d1c6a9b4cec632487e92 Mon Sep 17 00:00:00 2001 From: jawa0919 Date: Fri, 25 Jun 2021 18:08:54 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9E=20fix(Permission):=20some=20An?= =?UTF-8?q?droid=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1,fix 构建QRView时,onPermissionSet函数多次返回。2,fix 销毁QRView时,会展示权限弹窗 https://github.com/juliuscanute/qr_code_scanner/issues/305 --- .../kotlin/net/touchcapture/qr/flutterqr/QRView.kt | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) 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 b3d736c..87e97cb 100644 --- a/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt +++ b/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt @@ -102,8 +102,6 @@ class QRView(messenger: BinaryMessenger, id: Int, private val params: HashMap Date: Fri, 25 Jun 2021 18:49:19 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=90=9E=20fix(Permissions):=20miss=20o?= =?UTF-8?q?ther=20onRequestPermissionsResult?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/touchcapture/qr/flutterqr/QRView.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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 87e97cb..c05ec4a 100644 --- a/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt +++ b/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt @@ -273,14 +273,17 @@ class QRView(messenger: BinaryMessenger, id: Int, private val params: HashMap?, grantResults: IntArray): Boolean { - - if (requestCode == Shared.CAMERA_REQUEST_ID && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - permissionGranted = true - channel.invokeMethod("onPermissionSet", true) - return true + if(requestCode == Shared.CAMERA_REQUEST_ID) { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + permissionGranted = true + channel.invokeMethod("onPermissionSet", true) + return true + } else { + permissionGranted = false + channel.invokeMethod("onPermissionSet", false) + return false + } } - permissionGranted = false - channel.invokeMethod("onPermissionSet", false) return false }