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..c05ec4a 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?, 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 } 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();