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.

110 lines
3.6 KiB

2 years ago
<p align="center">
<img src="https://github.com/khoren93/flutter_zxing/blob/main/zxscanner/assets/images/app_logo.png" alt="ZXScanner logo" height="80" >
</p>
3 years ago
# flutter_zxing
A barcode and QR code scanner based on [ZXing C++](https://github.com/nu-book/zxing-cpp) library natively in Flutter with Dart FFI.
3 years ago
3 years ago
## Demo Screenshots
<pre>
3 years ago
<img alt="04_trending_repository_screen" src="https://user-images.githubusercontent.com/11523360/167903986-dc69efca-4520-4494-9298-24ea7b3da941.jpg" width="240">&nbsp; <img alt="04_trending_repository_screen" src="https://user-images.githubusercontent.com/11523360/167904002-114d9844-964d-4b84-9ea0-8185ed1d2bb8.jpg" width="240">&nbsp; <img alt="04_trending_repository_screen" src="https://user-images.githubusercontent.com/11523360/167904024-809aa434-c0f5-4069-a223-da78fe48d671.jpg" width="240">&nbsp;
3 years ago
</pre>
3 years ago
## Supported Barcode Formats
3 years ago
| 1D product | 1D industrial | 2D
| ---------- | ----------------- | --------------
| UPC-A | Code 39 | QR Code
| UPC-E | Code 93 | DataMatrix
| EAN-8 | Code 128 | Aztec
| EAN-13 | Codabar | PDF417
| DataBar | ITF | MaxiCode (beta)
| | DataBar Expanded |
3 years ago
## Features
3 years ago
- Scan barcode from camera stream
- Scan barcode from image path or url
- Create barcode from text
- Flashlight and pinch to zoom support
## Todo
- Read multiple barcodes from camera or gallery
- Return scanned barcode position and size
3 years ago
- Write tests
3 years ago
3 years ago
## Getting Started
### To read barcode:
```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
},
),
),
);
3 years ago
// Or use FlutterZxing
// To read barcode from camera image directly
3 years ago
await FlutterZxing.startCameraProcessing(); // Call this in initState
3 years ago
cameraController?.startImageStream((image) async {
CodeResult result = await FlutterZxing.processCameraImage(image);
3 years ago
if (result.isValidBool) {
debugPrint(result.textString);
}
return null;
});
3 years ago
FlutterZxing.stopCameraProcessing(); // Call this in dispose
3 years ago
// To read barcode from XFile, String or url
XFile xFile = XFile('Your image path');
CodeResult? resultFromXFile = await FlutterZxing.readImagePath(xFile);
String path = 'Your image path';
CodeResult? resultFromPath = await FlutterZxing.readImagePathString(path);
String url = 'Your image url';
CodeResult? resultFromUrl = await FlutterZxing.readImageUrl(url);
3 years ago
```
### To create barcode:
```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 text = 'Text to encode';
3 years ago
final result = FlutterZxing.encodeBarcode(text, 300, 300, Format.QRCode, 10, 0);
3 years ago
if (result.isValidBool) {
final img = imglib.Image.fromBytes(width, height, result.bytes);
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).