Skip to content

Commit

Permalink
Update dependencies and make code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rvndsngwn committed Feb 3, 2024
1 parent cefdaef commit e3e7650
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 56 deletions.
2 changes: 0 additions & 2 deletions .flutter-plugins

This file was deleted.

1 change: 0 additions & 1 deletion .flutter-plugins-dependencies

This file was deleted.

9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 3.4.3

- readme updated

## 3.4.2

- Dependency updates
- mobile_scanner: ^4.0.0

## 3.4.1

- Jump to 3.4.1 to match the version of mobile_scanner
Expand Down
58 changes: 35 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![pub package](https://img.shields.io/pub/v/ai_barcode_scanner.svg)](https://pub.dev/packages/ai_barcode_scanner)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/juliansteenbakker?label=Sponsor%20Julian%20Steenbakker!)](https://github.com/sponsors/juliansteenbakker)

### Screenshots
### Screenshots

<table>
<tr>
Expand All @@ -16,59 +16,72 @@
</tr>
</table>

## Platform Support

| Android | iOS | macOS | Web | Linux | Windows |
| ------- | --- | ----- | --- | ----- | ------- |
||||| :x: | :x: |

## Features Supported

See the example app for detailed implementation information.

| Features | Android | iOS | macOS | Web |
|------------------------|--------------------|--------------------|-------|-----|
| ---------------------- | ------------------ | ------------------ | ----- | --- |
| analyzeImage (Gallery) | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
| returnImage | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
| scanWindow | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
| barcodeOverlay | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |

## Platform Support

| Android | iOS | macOS | Web | Linux | Windows |
|---------|-----|-------|-----|-------|---------|
||||| :x: | :x: |
## Platform specific setup

### Android

This package uses by default the **bundled version** of MLKit Barcode-scanning for Android. This version is immediately available to the device. But it will increase the size of the app by approximately 3 to 10 MB.

## Platform specific setup
### Android
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.
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.
The alternative is to use the **unbundled version** of MLKit Barcode-scanning for Android. This version is downloaded on first use via Google Play Services. It increases the app size by around 600KB.

[You can read more about the difference between the two versions here.](https://developers.google.com/ml-kit/vision/barcode-scanning/android)

To use the **unbundled version** of the MLKit Barcode-scanning, add the following line to your `/android/gradle.properties` file:

```
dev.steenbakker.mobile_scanner.useUnbundled=true
```

### iOS

**Add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:**
NSCameraUsageDescription - describe why your app needs access to the camera. This is called Privacy - Camera Usage Description in the visual editor.

**If you want to use the local gallery feature from [image_picker](https://pub.dev/packages/image_picker)**
NSPhotoLibraryUsageDescription - describe why your app needs permission for the photo library. This is called Privacy - Photo Library Usage Description in the visual editor.

Example,
```
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to scan QR codes</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs photos access to get QR code from photo library</string>
```

```
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to scan QR codes</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs photos access to get QR code from photo library</string>
```

### macOS

Ensure that you granted camera permission in XCode -> Signing & Capabilities:

<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">

## Web

This package uses ZXing on web to read barcodes so it needs to be included in `index.html` as script.

```html
<script src="https://unpkg.com/@zxing/[email protected]" type="application/javascript"></script>
<script
src="https://unpkg.com/@zxing/[email protected]"
type="application/javascript"
></script>
```

## Usage ([ai_barcode_scanner](https://pub.dev/packages/ai_barcode_scanner))
Expand Down Expand Up @@ -123,7 +136,6 @@ AiBarcodeScanner(

## Usage ([mobile_scanner](https://pub.dev/packages/mobile_scanner))


## Usage

Import `package:mobile_scanner/mobile_scanner.dart`, and use the widget with or without the controller.
Expand Down Expand Up @@ -288,14 +300,14 @@ import 'package:mobile_scanner/mobile_scanner.dart';
The onDetect function returns a BarcodeCapture objects which contains the following items.

| Property name | Type | Description |
|---------------|---------------|-----------------------------------|
| ------------- | ------------- | --------------------------------- |
| barcodes | List<Barcode> | A list with scanned barcodes. |
| image | Uint8List? | If enabled, an image of the scan. |

You can use the following properties of the Barcode object.

| Property name | Type | Description |
|---------------|----------------|-------------------------------------|
| ------------- | -------------- | ----------------------------------- |
| format | BarcodeFormat | |
| rawBytes | Uint8List? | binary scan result |
| rawValue | String? | Value if barcode is in UTF-8 format |
Expand All @@ -314,7 +326,7 @@ You can use the following properties of the Barcode object.
### Constructor parameters for [ai_barcode_scanner](https://pub.dev/packages/ai_barcode_scanner)

```dart
/// Function that gets Called when barcode is scanned successfully
/// Function that gets Called when barcode is scanned successfully
///
final void Function(String) onScan;
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.4.1"
version: "3.4.2"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -195,10 +195,10 @@ packages:
dependency: transitive
description:
name: mobile_scanner
sha256: "2fbc3914fe625e196c64ea8ffc4084cd36781d2be276d4d5923b11af3b5d44ff"
sha256: "190506c3b0cf8a5a3c11e83de8c4f5ef4b6025a06c67d425a03f08129abf20d0"
url: "https://pub.dev"
source: hosted
version: "3.4.1"
version: "3.5.6"
path:
dependency: transitive
description:
Expand Down
14 changes: 9 additions & 5 deletions example/web/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html>

<head>
<!--
If you are serving your web app in a path other than the root, change the
Expand Down Expand Up @@ -27,7 +28,7 @@
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>
<link rel="icon" type="image/png" href="favicon.png" />

<title>example</title>
<link rel="manifest" href="manifest.json">
Expand All @@ -39,21 +40,24 @@
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jsQR.min.js"></script>
<script src="https://unpkg.com/@zxing/[email protected]" type="application/javascript"></script>
</head>

<body>
<script>
window.addEventListener('load', function(ev) {
window.addEventListener('load', function (ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
}
}).then(function(engineInitializer) {
}).then(function (engineInitializer) {
return engineInitializer.initializeEngine();
}).then(function(appRunner) {
}).then(function (appRunner) {
return appRunner.runApp();
});
});
</script>
</body>
</html>

</html>
37 changes: 17 additions & 20 deletions lib/src/ai_barcode_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class AiBarcodeScanner extends StatefulWidget {
final PreferredSizeWidget? appBar;

const AiBarcodeScanner({
Key? key,
super.key,
required this.onScan,
this.validator,
this.fit = BoxFit.cover,
Expand Down Expand Up @@ -157,7 +157,7 @@ class AiBarcodeScanner extends StatefulWidget {
this.startDelay,
this.bottomBar,
this.appBar,
}) : super(key: key);
});

@override
State<AiBarcodeScanner> createState() => _AiBarcodeScannerState();
Expand Down Expand Up @@ -189,10 +189,6 @@ class _AiBarcodeScannerState extends State<AiBarcodeScanner> {

@override
Widget build(BuildContext context) {
// /// keeps the app in portrait mode
// SystemChrome.setPreferredOrientations([
// DeviceOrientation.portraitUp,
// ]);
return OrientationBuilder(
builder: (context, orientation) {
return Scaffold(
Expand Down Expand Up @@ -338,21 +334,22 @@ class _AiBarcodeScannerState extends State<AiBarcodeScanner> {
},
),
),
IconButton(
tooltip: "Torch",
onPressed: () => controller.toggleTorch(),
icon: ValueListenableBuilder<TorchState>(
valueListenable: controller.torchState,
builder: (context, state, child) {
switch (state) {
case TorchState.off:
return const Icon(Icons.flash_off);
case TorchState.on:
return const Icon(Icons.flash_on);
}
},
if (controller.hasTorch)
IconButton(
tooltip: "Torch",
onPressed: () => controller.toggleTorch(),
icon: ValueListenableBuilder<TorchState>(
valueListenable: controller.torchState,
builder: (context, state, child) {
switch (state) {
case TorchState.off:
return const Icon(Icons.flash_off);
case TorchState.on:
return const Icon(Icons.flash_on);
}
},
),
),
),
],
),
),
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ai_barcode_scanner
description: A universal AI barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS.
version: 3.4.2
version: 3.4.3
homepage: https://mohesu.com
repository: https://github.com/mohesu/barcode_scanner.git
issue_tracker: https://github.com/mohesu/barcode_scanner/issues
Expand All @@ -23,7 +23,7 @@ dependencies:
flutter:
sdk: flutter

mobile_scanner: ^3.5.5
mobile_scanner: ^4.0.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit e3e7650

Please sign in to comment.