Flutter plugin for scanning and generating QR codes using the ZXing library, supporting Android, iOS, and desktop platforms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
6.7 KiB

# ZXScanner
2 years ago
<p align="center">
2 years ago
<img src="https://user-images.githubusercontent.com/11523360/178162663-57ec28ac-7075-43ab-ac31-35058298c73e.png" alt="ZXScanner logo" height="100" >
2 years ago
</p>
2 years ago
<p align="center">
2 years ago
<a href="https://apps.apple.com/am/app/zxscanner/id1629106248">
<img alt="Download on the App Store" title="App Store" src="https://user-images.githubusercontent.com/11523360/178162313-182568ae-c9a2-48bd-9a51-883562788d9e.png" height="50">
</a>
2 years ago
<a href="https://play.google.com/store/apps/details?id=com.markosyan.zxscanner">
<img alt="Download on the Google Play" title="Google Play" src="https://user-images.githubusercontent.com/11523360/178162318-533a29de-750f-4d4b-b117-f3d01c2c9340.png" height="50">
</a>
</p>
ZXScanner is a free QR code and barcode scanner app for Android and iOS. It is built using Flutter and the [flutter_zxing](https://github.com/khoren93/flutter_zxing) plugin.
3 years ago
3 years ago
## Demo Screenshots
2 years ago
3 years ago
<pre>
2 years ago
<img alt="01_scanner_screen" src="https://user-images.githubusercontent.com/11523360/214021992-7650c714-ebd9-4633-abc0-dcce5a36b2b8.png" width="240">&nbsp; <img alt="02_creator_screen" src="https://user-images.githubusercontent.com/11523360/214022172-025f09c7-65d9-494a-a663-232420d638db.png" width="240">&nbsp;
3 years ago
</pre>
2 years ago
All screenshots for iOS were generated using [Fastlane Snap](https://docs.fastlane.tools/actions/snapshot/). To generate your own, run the command:
```bash
cd zxscanner/ios
bundle exec fastlane screenshots
```
## Flutter ZXing
Flutter ZXing is a Flutter plugin for scanning and generating QR codes using the ZXing (Zebra Crossing) barcode scanning library. The plugin is implemented using the Dart FFI (Foreign Function Interface) and the [zxing-cpp](https://github.com/zxing-cpp/zxing-cpp) library, and allows you to easily integrate barcode scanning and generation functionality into your Flutter apps.
2 years ago
## Features
3 years ago
2 years ago
- Scan QR codes and barcodes from the camera stream (on mobile platforms only), image file or URL
- Scan multiple barcodes at once from the camera stream (on mobile platforms only), image file or URL
2 years ago
- Generate QR codes with customizable content and size
- Return the position points of the scanned barcode
- Customizable scanner frame size and color, and ability to enable or disable features like torch and pinch to zoom
3 years ago
2 years ago
## Supported Formats
| Linear product | Linear industrial | Matrix |
|----------------|-------------------|--------------------|
| UPC-A | Code 39 | QR Code |
| UPC-E | Code 93 | Micro QR Code |
| EAN-8 | Code 128 | Aztec |
| EAN-13 | Codabar | DataMatrix |
| DataBar | DataBar Expanded | PDF417 |
| | ITF | MaxiCode (partial) |
## Supported platforms
Flutter ZXing supports the following platforms:
- Android (minimum API level 21)
- iOS (minimum iOS 11.0)
- MacOS (minimum osx 10.15) (beta)
- Linux (beta)
- Windows (beta)
Note that flutter_zxing relies on the Dart FFI (Foreign Function Interface) feature, which is currently only available for the mobile and desktop platforms. As a result, the plugin is not currently supported on the web platform.
2 years ago
2 years ago
In addition, flutter_zxing uses the camera plugin to access the device's camera for scanning barcodes. This plugin is only supported on mobile platforms, and is not available for desktop platforms. Therefore, some features of flutter_zxing, such as scanning barcodes using the camera, are not available on desktop platforms.
3 years ago
2 years ago
## Generated by [ChatGPT](https://chat.openai.com/chat)
2 years ago
2 years ago
This README file was mainly generated using ChatGPT, a tool that generates human-like text.
3 years ago
3 years ago
## Getting Started
2 years ago
### Cloning the flutter_zxing project
To clone the flutter_zxing project from Github which includes submodules, use the following command:
```bash
git clone --recursive https://github.com/khoren93/flutter_zxing.git
```
### Installing dependencies
Use Melos to install the dependencies of the flutter_zxing project. Melos is a tool that helps you manage multiple Dart packages in a single repository. To install Melos, use the following command:
```bash
flutter pub global activate melos
```
To install the dependencies of the flutter_zxing project, use the following command:
```bash
melos bootstrap
```
To allow the building on iOS and MacOS, you need to run the following command:
```bash
cd scripts
sh update_ios_macos_src.sh
```
Now you can run the flutter_zxing example app on your device or emulator.
## Usage
2 years ago
### To read barcode
3 years ago
```dart
import 'package:flutter_zxing/flutter_zxing.dart';
3 years ago
// Use ReaderWidget to quickly read barcode from camera image
3 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
3 years ago
body: ReaderWidget(
3 years ago
onScan: (result) async {
// Do something with the result
},
),
),
);
// Or use flutter_zxing plugin methods
3 years ago
// To read barcode from camera image directly
2 years ago
await zx.startCameraProcessing(); // Call this in initState
3 years ago
cameraController?.startImageStream((image) async {
2 years ago
Code result = await zx.processCameraImage(image);
if (result.isValid) {
debugPrint(result.text);
3 years ago
}
return null;
});
2 years ago
zx.stopCameraProcessing(); // Call this in dispose
3 years ago
2 years ago
// To read barcode from XFile, String, url or Uint8List bytes
3 years ago
XFile xFile = XFile('Your image path');
2 years ago
Code? resultFromXFile = await zx.readBarcodeImagePath(xFile);
3 years ago
2 years ago
String path = 'Your local image path';
2 years ago
Code? resultFromPath = await zx.readBarcodeImagePathString(path);
3 years ago
2 years ago
String url = 'Your remote image url';
2 years ago
Code? resultFromUrl = await zx.readBarcodeImageUrl(url);
2 years ago
Uint8List bytes = Uint8List.fromList(yourImageBytes);
2 years ago
Code? resultFromBytes = await zx.readBarcode(bytes);
3 years ago
```
2 years ago
### To create barcode
3 years ago
```dart
import 'package:flutter_zxing/flutter_zxing.dart';
import 'dart:typed_data';
import 'package:image/image.dart' as imglib;
3 years ago
// Use WriterWidget to quickly create barcode
3 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
3 years ago
body: WriterWidget(
3 years ago
onSuccess: (result, bytes) {
// Do something with the result
},
onError: (error) {
// Do something with the error
},
),
),
);
// Or use FlutterZxing to create barcode directly
final Encode result = zx.encodeBarcode(
contents: 'Text to encode',
params: EncodeParams(
format: Format.QRCode,
width: 120,
height: 120,
margin: 10,
eccLevel: EccLevel.low,
),
);
2 years ago
if (result.isValid) {
2 years ago
final img = imglib.Image.fromBytes(width, height, result.data);
3 years ago
final encodedBytes = Uint8List.fromList(imglib.encodeJpg(img));
// use encodedBytes as you wish
}
```
## License
3 years ago
MIT License. See [LICENSE](https://github.com/khoren93/flutter_zxing/blob/master/LICENSE).