Julian Steenbakker

Merge remote-tracking branch 'origin/fix_android_permission_bug' into fix_android_permission_bug

@@ -11,8 +11,8 @@ jobs: @@ -11,8 +11,8 @@ jobs:
11 analysis: 11 analysis:
12 runs-on: ubuntu-latest 12 runs-on: ubuntu-latest
13 steps: 13 steps:
14 - - uses: actions/checkout@v3.1.0  
15 - - uses: actions/setup-java@v3.6.0 14 + - uses: actions/checkout@v3.2.0
  15 + - uses: actions/setup-java@v3.8.0
16 with: 16 with:
17 java-version: 11 17 java-version: 11
18 distribution: temurin 18 distribution: temurin
@@ -28,8 +28,8 @@ jobs: @@ -28,8 +28,8 @@ jobs:
28 formatting: 28 formatting:
29 runs-on: ubuntu-latest 29 runs-on: ubuntu-latest
30 steps: 30 steps:
31 - - uses: actions/checkout@v3.1.0  
32 - - uses: actions/setup-java@v3.6.0 31 + - uses: actions/checkout@v3.2.0
  32 + - uses: actions/setup-java@v3.8.0
33 with: 33 with:
34 java-version: 11 34 java-version: 11
35 distribution: temurin 35 distribution: temurin
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 release-please: 7 release-please:
8 runs-on: ubuntu-latest 8 runs-on: ubuntu-latest
9 steps: 9 steps:
10 - - uses: GoogleCloudPlatform/release-please-action@v3.6.1 10 + - uses: GoogleCloudPlatform/release-please-action@v3.7.0
11 with: 11 with:
12 token: ${{ secrets.GITHUB_TOKEN }} 12 token: ${{ secrets.GITHUB_TOKEN }}
13 release-type: simple 13 release-type: simple
@@ -28,6 +28,8 @@ Improvements: @@ -28,6 +28,8 @@ Improvements:
28 * Removed `called stop while already stopped` messages. 28 * Removed `called stop while already stopped` messages.
29 29
30 Features: 30 Features:
  31 +* You can now provide a `scanWindow` to the `MobileScanner()` widget.
  32 +* You can now draw an overlay over the scanned barcode. See the barcode scanner window in the example app for more information.
31 * Added a new `placeholderBuilder` function to the `MobileScanner` widget to customize the preview placeholder. 33 * Added a new `placeholderBuilder` function to the `MobileScanner` widget to customize the preview placeholder.
32 * Added `autoStart` parameter to MobileScannerController(). If set to false, controller won't start automatically. 34 * Added `autoStart` parameter to MobileScannerController(). If set to false, controller won't start automatically.
33 * Added `hasTorch` function on MobileScannerController(). After starting the controller, you can check if the device has a torch. 35 * Added `hasTorch` function on MobileScannerController(). After starting the controller, you can check if the device has a torch.
@@ -3,40 +3,42 @@ @@ -3,40 +3,42 @@
3 [![pub package](https://img.shields.io/pub/v/mobile_scanner.svg)](https://pub.dev/packages/mobile_scanner) 3 [![pub package](https://img.shields.io/pub/v/mobile_scanner.svg)](https://pub.dev/packages/mobile_scanner)
4 [![style: lint](https://img.shields.io/badge/style-lint-4BC0F5.svg)](https://pub.dev/packages/lint) 4 [![style: lint](https://img.shields.io/badge/style-lint-4BC0F5.svg)](https://pub.dev/packages/lint)
5 [![mobile_scanner](https://github.com/juliansteenbakker/mobile_scanner/actions/workflows/flutter.yml/badge.svg)](https://github.com/juliansteenbakker/mobile_scanner/actions/workflows/flutter.yml) 5 [![mobile_scanner](https://github.com/juliansteenbakker/mobile_scanner/actions/workflows/flutter.yml/badge.svg)](https://github.com/juliansteenbakker/mobile_scanner/actions/workflows/flutter.yml)
6 -[![GitHub Sponsors](https://img.shields.io/github/sponsors/juliansteenbakker?label=sponsor%20me)](https://github.com/sponsors/juliansteenbakker) 6 +[![GitHub Sponsors](https://img.shields.io/github/sponsors/juliansteenbakker?label=like%20my%20work?%20sponsor%20me!)](https://github.com/sponsors/juliansteenbakker)
7 7
8 -A universal barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS. 8 +An universal barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS.
9 9
10 -## Platform Support 10 +## Features Supported
11 11
12 -| Android | iOS | MacOS | Web | Linux | Windows |  
13 -| :-----: | :-: | :---: | :-: | :---: | :-----: |  
14 -| ✔️ | ✔️ | ✔️ | ✔️ | | | 12 +See the example app for detailed implementation information.
15 13
16 -### Android  
17 -SDK 21 and newer. Reason: CameraX requires at least SDK 21.  
18 -Also, make sure you upgrade kotlin to the latest version in your project. 14 +| Features | Android | iOS | macOS | Web |
  15 +|------------------------|--------------------|--------------------|-------|-----|
  16 +| analyzeImage (Gallery) | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
  17 +| returnImage | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
  18 +| scanWindow | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
  19 +| barcodeOverlay | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
  20 +
  21 +## Platform Support
19 22
20 -This packages uses the **bundled version** of MLKit Barcode-scanning for Android. This version is more accurate and immediately available to devices. However, this version will increas the size of the app with approximately 3 to 10 MB. The alternative for this is to use the **unbundled version** of MLKit Barcode-scanning for Android. This version is older than the bundled version however this only increases the size by around 600KB. 23 +| Android | iOS | macOS | Web | Linux | Windows |
  24 +|---------|-----|-------|-----|-------|---------|
  25 +| ✔ | ✔ | ✔ | ✔ | :x: | :x: |
21 26
  27 +## Platform specific setup
  28 +### Android
  29 +This packages uses the **bundled version** of MLKit Barcode-scanning for Android. This version is more accurate and immediately available to devices. However, this version will increase the size of the app with approximately 3 to 10 MB. The alternative for this is to use the **unbundled version** of MLKit Barcode-scanning for Android. This version is older than the bundled version however this only increases the size by around 600KB.
22 To use this version you must alter the mobile_scanner gradle file to replace `com.google.mlkit:barcode-scanning:17.0.2` with `com.google.android.gms:play-services-mlkit-barcode-scanning:18.0.0`. Keep in mind that if you alter the gradle files directly in your project it can be overriden when you update your pubspec.yaml. I am still searching for a way to properly replace the module in gradle but have yet to find one. 30 To use this version you must alter the mobile_scanner gradle file to replace `com.google.mlkit:barcode-scanning:17.0.2` with `com.google.android.gms:play-services-mlkit-barcode-scanning:18.0.0`. Keep in mind that if you alter the gradle files directly in your project it can be overriden when you update your pubspec.yaml. I am still searching for a way to properly replace the module in gradle but have yet to find one.
23 31
24 [You can read more about the difference between the two versions here.](https://developers.google.com/ml-kit/vision/barcode-scanning/android) 32 [You can read more about the difference between the two versions here.](https://developers.google.com/ml-kit/vision/barcode-scanning/android)
25 33
26 ### iOS 34 ### iOS
27 -iOS 11 and newer. Reason: MLKit for iOS requires at least iOS 10 and a [64bit device](https://developers.google.com/ml-kit/migration/ios).  
28 -  
29 **Add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:** 35 **Add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:**
30 -  
31 NSCameraUsageDescription - describe why your app needs access to the camera. This is called Privacy - Camera Usage Description in the visual editor. 36 NSCameraUsageDescription - describe why your app needs access to the camera. This is called Privacy - Camera Usage Description in the visual editor.
32 37
33 **If you want to use the local gallery feature from [image_picker](https://pub.dev/packages/image_picker)** 38 **If you want to use the local gallery feature from [image_picker](https://pub.dev/packages/image_picker)**
34 -  
35 NSPhotoLibraryUsageDescription - describe why your app needs permission for the photo library. This is called Privacy - Photo Library Usage Description in the visual editor. 39 NSPhotoLibraryUsageDescription - describe why your app needs permission for the photo library. This is called Privacy - Photo Library Usage Description in the visual editor.
36 40
37 ### macOS 41 ### macOS
38 -macOS 10.13 or newer. Reason: Apple Vision library.  
39 -  
40 Ensure that you granted camera permission in XCode -> Signing & Capabilities: 42 Ensure that you granted camera permission in XCode -> Signing & Capabilities:
41 43
42 <img width="696" alt="Screenshot of XCode where Camera is checked" src="https://user-images.githubusercontent.com/24459435/193464115-d76f81d0-6355-4cb2-8bee-538e413a3ad0.png"> 44 <img width="696" alt="Screenshot of XCode where Camera is checked" src="https://user-images.githubusercontent.com/24459435/193464115-d76f81d0-6355-4cb2-8bee-538e413a3ad0.png">
@@ -48,12 +50,6 @@ Add this to `web/index.html`: @@ -48,12 +50,6 @@ Add this to `web/index.html`:
48 <script type="text/javascript" src="https://unpkg.com/@zxing/library@0.19.1"></script> 50 <script type="text/javascript" src="https://unpkg.com/@zxing/library@0.19.1"></script>
49 ``` 51 ```
50 52
51 -## Features Supported  
52 -  
53 -| Features | Android | iOS | macOS | Web |  
54 -|------------------------|--------------------|--------------------|-------|-----|  
55 -| analyzeImage (Gallery) | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |  
56 -  
57 ## Usage 53 ## Usage
58 54
59 Import `package:mobile_scanner/mobile_scanner.dart`, and use the widget with or without the controller. 55 Import `package:mobile_scanner/mobile_scanner.dart`, and use the widget with or without the controller.
@@ -49,10 +49,10 @@ dependencies { @@ -49,10 +49,10 @@ dependencies {
49 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 49 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
50 50
51 // Use this dependency to bundle the model with your app 51 // Use this dependency to bundle the model with your app
52 - implementation 'com.google.mlkit:barcode-scanning:17.0.2' 52 + implementation 'com.google.mlkit:barcode-scanning:17.0.3'
53 // Use this dependency to use the dynamically downloaded model in Google Play Services 53 // Use this dependency to use the dynamically downloaded model in Google Play Services
54 // implementation 'com.google.android.gms:play-services-mlkit-barcode-scanning:18.1.0' 54 // implementation 'com.google.android.gms:play-services-mlkit-barcode-scanning:18.1.0'
55 55
56 - implementation 'androidx.camera:camera-camera2:1.1.0'  
57 - implementation 'androidx.camera:camera-lifecycle:1.1.0' 56 + implementation 'androidx.camera:camera-camera2:1.2.0'
  57 + implementation 'androidx.camera:camera-lifecycle:1.2.0'
58 } 58 }
@@ -54,11 +54,10 @@ class _BarcodeScannerWithScanWindowState @@ -54,11 +54,10 @@ class _BarcodeScannerWithScanWindowState
54 arguments != null) 54 arguments != null)
55 CustomPaint( 55 CustomPaint(
56 painter: BarcodeOverlay( 56 painter: BarcodeOverlay(
57 - barcode!,  
58 - arguments!,  
59 - BoxFit.contain,  
60 - MediaQuery.of(context).devicePixelRatio,  
61 - capture!, 57 + barcode: barcode!,
  58 + arguments: arguments!,
  59 + boxFit: BoxFit.contain,
  60 + capture: capture!,
62 ), 61 ),
63 ), 62 ),
64 CustomPaint( 63 CustomPaint(
@@ -131,19 +130,17 @@ class ScannerOverlay extends CustomPainter { @@ -131,19 +130,17 @@ class ScannerOverlay extends CustomPainter {
131 } 130 }
132 131
133 class BarcodeOverlay extends CustomPainter { 132 class BarcodeOverlay extends CustomPainter {
134 - BarcodeOverlay(  
135 - this.barcode,  
136 - this.arguments,  
137 - this.boxFit,  
138 - this.devicePixelRatio,  
139 - this.capture,  
140 - ); 133 + BarcodeOverlay({
  134 + required this.barcode,
  135 + required this.arguments,
  136 + required this.boxFit,
  137 + required this.capture,
  138 + });
141 139
142 final BarcodeCapture capture; 140 final BarcodeCapture capture;
143 final Barcode barcode; 141 final Barcode barcode;
144 final MobileScannerArguments arguments; 142 final MobileScannerArguments arguments;
145 final BoxFit boxFit; 143 final BoxFit boxFit;
146 - final double devicePixelRatio;  
147 144
148 @override 145 @override
149 void paint(Canvas canvas, Size size) { 146 void paint(Canvas canvas, Size size) {
@@ -218,6 +218,8 @@ class _MobileScannerState extends State<MobileScanner> @@ -218,6 +218,8 @@ class _MobileScannerState extends State<MobileScanner>
218 ); 218 );
219 } 219 }
220 220
  221 + Rect? scanWindow;
  222 +
221 @override 223 @override
222 Widget build(BuildContext context) { 224 Widget build(BuildContext context) {
223 return LayoutBuilder( 225 return LayoutBuilder(
@@ -229,14 +231,14 @@ class _MobileScannerState extends State<MobileScanner> @@ -229,14 +231,14 @@ class _MobileScannerState extends State<MobileScanner>
229 return __buildPlaceholderOrError(context, child); 231 return __buildPlaceholderOrError(context, child);
230 } 232 }
231 233
232 - if (widget.scanWindow != null) {  
233 - final window = calculateScanWindowRelativeToTextureInPercentage( 234 + if (widget.scanWindow != null && scanWindow == null) {
  235 + scanWindow = calculateScanWindowRelativeToTextureInPercentage(
234 widget.fit, 236 widget.fit,
235 widget.scanWindow!, 237 widget.scanWindow!,
236 value.size, 238 value.size,
237 Size(constraints.maxWidth, constraints.maxHeight), 239 Size(constraints.maxWidth, constraints.maxHeight),
238 ); 240 );
239 - _controller.updateScanWindow(window); 241 + _controller.updateScanWindow(scanWindow!);
240 } 242 }
241 243
242 return ClipRect( 244 return ClipRect(
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 # 4 #
5 Pod::Spec.new do |s| 5 Pod::Spec.new do |s|
6 s.name = 'mobile_scanner' 6 s.name = 'mobile_scanner'
7 - s.version = '0.0.1' 7 + s.version = '3.0.0'
8 s.summary = 'An universal scanner for Flutter based on MLKit.' 8 s.summary = 'An universal scanner for Flutter based on MLKit.'
9 s.description = <<-DESC 9 s.description = <<-DESC
10 An universal scanner for Flutter based on MLKit. 10 An universal scanner for Flutter based on MLKit.