Julian Steenbakker
Committed by GitHub

Merge branch 'master' into dependabot/gradle/android/com.android.tools.build-gradle-7.3.0

  1 +# These owners will be the default owners for everything in
  2 +# the repo. Unless a later match takes precedence,
  3 +# review when someone opens a pull request.
  4 +# For more on how to customize the CODEOWNERS file - https://help.github.com/en/articles/about-code-owners
  5 +
  6 +* @juliansteenbakker
  1 +# .github/workflows/auto-author-assign.yml
  2 +name: 'Auto Author Assign'
  3 +
  4 +on:
  5 + pull_request_target:
  6 + types: [opened, reopened]
  7 +
  8 +permissions:
  9 + pull-requests: write
  10 +
  11 +jobs:
  12 + assign-author:
  13 + runs-on: ubuntu-latest
  14 + steps:
  15 + - uses: toshimaru/auto-author-assign@v1.6.1
@@ -6,7 +6,7 @@ buildscript { @@ -6,7 +6,7 @@ buildscript {
6 } 6 }
7 7
8 dependencies { 8 dependencies {
9 - classpath 'com.android.tools.build:gradle:7.2.2' 9 + classpath 'com.android.tools.build:gradle:7.3.0'
10 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 10 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 } 11 }
12 } 12 }
@@ -195,13 +195,13 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan @@ -195,13 +195,13 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan
195 let facing: Int = argReader.int(key: "facing") ?? 1 195 let facing: Int = argReader.int(key: "facing") ?? 1
196 let formats: Array = argReader.intArray(key: "formats") ?? [] 196 let formats: Array = argReader.intArray(key: "formats") ?? []
197 197
198 - let formatList: NSMutableArray = [] 198 + if (formats.count != 0) {
  199 + var barcodeFormats: BarcodeFormat = []
199 for index in formats { 200 for index in formats {
200 - formatList.add(BarcodeFormat(rawValue: index)) 201 + barcodeFormats.insert(BarcodeFormat(rawValue: index))
201 } 202 }
202 203
203 - if (formatList.count != 0) {  
204 - let barcodeOptions = BarcodeScannerOptions(formats: formatList.firstObject as! BarcodeFormat) 204 + let barcodeOptions = BarcodeScannerOptions(formats: barcodeFormats)
205 scanner = BarcodeScanner.barcodeScanner(options: barcodeOptions) 205 scanner = BarcodeScanner.barcodeScanner(options: barcodeOptions)
206 } 206 }
207 207
@@ -24,7 +24,6 @@ class MobileScannerWebPlugin { @@ -24,7 +24,6 @@ class MobileScannerWebPlugin {
24 registrar, 24 registrar,
25 ); 25 );
26 final MobileScannerWebPlugin instance = MobileScannerWebPlugin(); 26 final MobileScannerWebPlugin instance = MobileScannerWebPlugin();
27 - WidgetsFlutterBinding.ensureInitialized();  
28 27
29 channel.setMethodCallHandler(instance.handleMethodCall); 28 channel.setMethodCallHandler(instance.handleMethodCall);
30 event.setController(instance.controller); 29 event.setController(instance.controller);
@@ -9,6 +9,9 @@ class MobileScanner extends StatefulWidget { @@ -9,6 +9,9 @@ class MobileScanner extends StatefulWidget {
9 /// The controller of the camera. 9 /// The controller of the camera.
10 final MobileScannerController? controller; 10 final MobileScannerController? controller;
11 11
  12 + /// Calls the provided [onPermissionSet] callback when the permission is set.
  13 + final Function(bool permissionGranted)? onPermissionSet;
  14 +
12 /// Function that gets called when a Barcode is detected. 15 /// Function that gets called when a Barcode is detected.
13 /// 16 ///
14 /// [barcode] The barcode object with all information about the scanned code. 17 /// [barcode] The barcode object with all information about the scanned code.
@@ -34,6 +37,7 @@ class MobileScanner extends StatefulWidget { @@ -34,6 +37,7 @@ class MobileScanner extends StatefulWidget {
34 this.controller, 37 this.controller,
35 this.fit = BoxFit.cover, 38 this.fit = BoxFit.cover,
36 this.allowDuplicates = false, 39 this.allowDuplicates = false,
  40 + this.onPermissionSet,
37 }); 41 });
38 42
39 @override 43 @override
@@ -48,7 +52,8 @@ class _MobileScannerState extends State<MobileScanner> @@ -48,7 +52,8 @@ class _MobileScannerState extends State<MobileScanner>
48 void initState() { 52 void initState() {
49 super.initState(); 53 super.initState();
50 WidgetsBinding.instance.addObserver(this); 54 WidgetsBinding.instance.addObserver(this);
51 - controller = widget.controller ?? MobileScannerController(); 55 + controller = widget.controller ??
  56 + MobileScannerController(onPermissionSet: widget.onPermissionSet);
52 if (!controller.isStarting) controller.start(); 57 if (!controller.isStarting) controller.start();
53 } 58 }
54 59
@@ -118,7 +123,8 @@ class _MobileScannerState extends State<MobileScanner> @@ -118,7 +123,8 @@ class _MobileScannerState extends State<MobileScanner>
118 } 123 }
119 } else { 124 } else {
120 if (widget.controller == null) { 125 if (widget.controller == null) {
121 - controller = MobileScannerController(); 126 + controller =
  127 + MobileScannerController(onPermissionSet: widget.onPermissionSet);
122 } else if (oldWidget.controller != widget.controller) { 128 } else if (oldWidget.controller != widget.controller) {
123 controller = widget.controller!; 129 controller = widget.controller!;
124 } 130 }
1 import 'dart:async'; 1 import 'dart:async';
2 import 'dart:io'; 2 import 'dart:io';
3 -import 'dart:typed_data';  
4 3
5 import 'package:flutter/cupertino.dart'; 4 import 'package:flutter/cupertino.dart';
6 import 'package:flutter/foundation.dart'; 5 import 'package:flutter/foundation.dart';
@@ -40,6 +39,7 @@ class MobileScannerController { @@ -40,6 +39,7 @@ class MobileScannerController {
40 static int? _controllerHashcode; 39 static int? _controllerHashcode;
41 StreamSubscription? events; 40 StreamSubscription? events;
42 41
  42 + Function(bool permissionGranted)? onPermissionSet;
43 final ValueNotifier<MobileScannerArguments?> args = ValueNotifier(null); 43 final ValueNotifier<MobileScannerArguments?> args = ValueNotifier(null);
44 final ValueNotifier<TorchState> torchState = ValueNotifier(TorchState.off); 44 final ValueNotifier<TorchState> torchState = ValueNotifier(TorchState.off);
45 late final ValueNotifier<CameraFacing> cameraFacingState; 45 late final ValueNotifier<CameraFacing> cameraFacingState;
@@ -49,8 +49,6 @@ class MobileScannerController { @@ -49,8 +49,6 @@ class MobileScannerController {
49 final bool returnImage; 49 final bool returnImage;
50 50
51 /// If provided, the scanner will only detect those specific formats. 51 /// If provided, the scanner will only detect those specific formats.
52 - ///  
53 - /// WARNING: On iOS, only 1 format is supported.  
54 final List<BarcodeFormat>? formats; 52 final List<BarcodeFormat>? formats;
55 53
56 CameraFacing facing; 54 CameraFacing facing;
@@ -67,6 +65,7 @@ class MobileScannerController { @@ -67,6 +65,7 @@ class MobileScannerController {
67 this.ratio, 65 this.ratio,
68 this.torchEnabled, 66 this.torchEnabled,
69 this.formats, 67 this.formats,
  68 + this.onPermissionSet,
70 this.autoResume = true, 69 this.autoResume = true,
71 this.returnImage = false, 70 this.returnImage = false,
72 }) { 71 }) {
@@ -157,11 +156,14 @@ class MobileScannerController { @@ -157,11 +156,14 @@ class MobileScannerController {
157 state = result 156 state = result
158 ? MobileScannerState.authorized 157 ? MobileScannerState.authorized
159 : MobileScannerState.denied; 158 : MobileScannerState.denied;
  159 + onPermissionSet?.call(result);
160 break; 160 break;
161 case MobileScannerState.denied: 161 case MobileScannerState.denied:
162 isStarting = false; 162 isStarting = false;
  163 + onPermissionSet?.call(false);
163 throw PlatformException(code: 'NO ACCESS'); 164 throw PlatformException(code: 'NO ACCESS');
164 case MobileScannerState.authorized: 165 case MobileScannerState.authorized:
  166 + onPermissionSet?.call(true);
165 break; 167 break;
166 } 168 }
167 } 169 }
@@ -193,6 +195,9 @@ class MobileScannerController { @@ -193,6 +195,9 @@ class MobileScannerController {
193 } on PlatformException catch (error) { 195 } on PlatformException catch (error) {
194 debugPrint('${error.code}: ${error.message}'); 196 debugPrint('${error.code}: ${error.message}');
195 isStarting = false; 197 isStarting = false;
  198 + if (error.code == "MobileScannerWeb") {
  199 + onPermissionSet?.call(false);
  200 + }
196 // setAnalyzeMode(AnalyzeMode.none.index); 201 // setAnalyzeMode(AnalyzeMode.none.index);
197 return; 202 return;
198 } 203 }
@@ -205,6 +210,10 @@ class MobileScannerController { @@ -205,6 +210,10 @@ class MobileScannerController {
205 hasTorch = startResult['torchable'] as bool? ?? false; 210 hasTorch = startResult['torchable'] as bool? ?? false;
206 211
207 if (kIsWeb) { 212 if (kIsWeb) {
  213 + onPermissionSet?.call(
  214 + true,
  215 + ); // If we reach this line, it means camera permission has been granted
  216 +
208 args.value = MobileScannerArguments( 217 args.value = MobileScannerArguments(
209 webId: startResult['ViewID'] as String?, 218 webId: startResult['ViewID'] as String?,
210 size: Size( 219 size: Size(
@@ -288,6 +297,7 @@ class MobileScannerController { @@ -288,6 +297,7 @@ class MobileScannerController {
288 events?.cancel(); 297 events?.cancel();
289 events = null; 298 events = null;
290 _controllerHashcode = null; 299 _controllerHashcode = null;
  300 + onPermissionSet = null;
291 } 301 }
292 barcodesController.close(); 302 barcodesController.close();
293 } 303 }