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.

129 lines
4.1 KiB

3 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" >
3 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>
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
2 years ago
3 years ago
## Demo Screenshots
<pre>
2 years ago
<img alt="01_scanner_screen" src="https://user-images.githubusercontent.com/11523360/174789425-b33861aa-dbe5-49c1-a84a-a02b514a5e0f.png" width="240">&nbsp; <img alt="02_creator_screen" src="https://user-images.githubusercontent.com/11523360/174789816-a2a4ab74-f5ef-41a1-98f3-e514447dff5a.png" 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
2 years ago
- Scan barcode from camera stream, image path or url
- Scan multiple barcodes from camera stream, image path or url
3 years ago
- Create barcode from text
2 years ago
- Return scanned barcode position points
3 years ago
- Flashlight and pinch to zoom support
## Todo
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
},
),
),
);
// Or use flutter_zxing plugin methods
3 years ago
// To read barcode from camera image directly
await startCameraProcessing(); // Call this in initState
3 years ago
cameraController?.startImageStream((image) async {
CodeResult result = await processCameraImage(image);
3 years ago
if (result.isValidBool) {
debugPrint(result.textString);
}
return null;
});
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
CodeResult? resultFromXFile = await readBarcodeImagePath(xFile);
3 years ago
2 years ago
String path = 'Your local image path';
CodeResult? resultFromPath = await readBarcodeImagePathString(path);
3 years ago
2 years ago
String url = 'Your remote image url';
CodeResult? resultFromUrl = await readBarcodeImageUrl(url);
Uint8List bytes = Uint8List.fromList(yourImageBytes);
CodeResult? resultFromBytes = await readBarcode(bytes);
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 result = encodeBarcode(
'Text to encode',
format: Format.QRCode,
width: 300,
height: 300,
margin: 10,
eccLevel: 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).