सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
flutter_zxing एक Flutter पैकेज है जो Dart FFI के माध्यम से ZXing लाइब्रेरी का उपयोग करके मूल बारकोड स्कैनिंग और उत्पादन की अनुमति देता है। यह Android, iOS, macOS, Windows और Linux पर QR कोड और बारकोड को पढ़ने और बनाने के लिए उच्च प्रदर्शन वाले क्रॉस-प्लेटफॉर्म कार्यक्षमता प्रदान करता है। पैकेज Flutter के UI के साथ बिना किसी बाधा के एकीकृत है और ऑप्टिमल गति और सटीकता के लिए मूल कोड का उपयोग करता है। यह रियल-टाइम स्कैनिंग और कस्टमाइज़ किए गए कैमरा सेटिंग्स का समर्थन करता है, जिससे यह विश्वसनीय बारकोड इंटरैक्शन की आवश्यकता वाले एप्लिकेशन के लिए आदर्श है।
उपयोग
मोबाइल इन्वेंटरी प्रबंधन
डिजिटल टिकटिंग प्रणाली
उत्पाद जानकारी खोज
QR कोड के माध्यम से संपर्क साझा करें
भुगतान कोड स्कैनिंग
मुख्य विशेषताएँ
Dart FFI के माध्यम से मूल प्रदर्शन
क्रॉस-प्लेटफ़ॉर्म समर्थन
रियल-टाइम बारकोड स्कैनिंग
कस्टमाइज़ेबल कैमरा सेटिंग्स
QR कोड और बारकोड उत्पादन
इनके लिए उपयुक्त
त्वरित बारकोड स्कैनिंग की आवश्यकता वाले ऐप्स
मूल स्तर के प्रदर्शन की तलाश में विकासकर्ता
बहुप्लेटफॉर्म मोबाइल एप्लिकेशन
रिटेल और लॉजिस्टिक्स सॉफ्टवेयर
घटना या टिकटिंग प्लेटफॉर्म
विचार योग्य बातें
सभी प्लेटफॉर्म पर कैमरा अनुमति की आवश्यकता होती है
वेब के लिए अतिरिक्त कॉन्फ़िगरेशन की आवश्यकता हो सकती है
समर्थित प्लेटफॉर्म तक सीमित (डिफ़ॉल्ट रूप से वेब नहीं)
कैमरा प्रीव्यू के लिए कस्टम विजेट हैंडलिंग की आवश्यकता हो सकती है
बिल्ड सेटअप प्लेटफॉर्म के अनुसार थोड़ा अलग हो सकता है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
Flutter ZXing
Flutter ZXing is a high-performance Flutter plugin for scanning and generating QR codes and barcodes. Built on the powerful ZXing C++ library, it provides fast and reliable barcode processing capabilities for Flutter applications. Whether you need to scan barcodes from the camera or generate custom QR codes, Flutter ZXing makes it seamless and efficient.
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:
flutter pub global activate melos
To install the dependencies of the flutter_zxing project, use the following command:
melos bootstrap
To allow the building on iOS and MacOS, you need to run the following command:
./scripts/update_ios_macos_src.sh
To run the integration tests:
cd example
flutter test integration_test
Now you can run the flutter_zxing example app on your device or emulator.
Use with dependency_overrides
If you want to use a forked version of the flutter_zxing library in your project, you can specify it using dependency_overrides in your pubspec.yaml. However, be aware that flutter_zxing relies on the ZXing C++ code included as a git submodule. When using dependency_overrides with a git repository, these submodules are not automatically included, and the update_ios_macos_src.sh script is not run, which can lead to errors, especially on iOS.
Your project might build but encounter runtime errors due to missing library exports that appear as an error like this: flutter: type 'ArgumentError' is not a subtype of type 'Code' in type cast
Recommended Approach: Using a Git Submodule
To ensure all necessary files are present, it's recommended to add your forked repository as a git submodule, initialize the submodules recursively, and reference it using a local path. Follow these steps:
In your project add your fork as a submodule and initialize it recursively.
Run the scripts/update_ios_macos_src.sh script to update the iOS and MacOS source files. (Or add it to your own projects build process)
Run flutter clean to clear the build cache.
Build and run your project.
Why Not Use a Direct Git Reference?
Referencing your forked repo as a direct git reference in the depenency_overrides section of the pubspec.yaml does not include submodules or run the update_ios_macos_src.sh script. Manually running these steps in the .pub-cache directory is not practical, since the path changes with each commit.
Usage
To read barcode
flutter_zxing re-exports the camera types that appear in its own API
(CameraImage, XFile, CameraController, ...), so a single import is enough.
import'package:flutter_zxing/flutter_zxing.dart';
// Use ReaderWidget to quickly read barcode from camera image@overrideWidgetbuild(BuildContext context) {
returnScaffold(
body: ReaderWidget(
onScan: (result) async {
// Do something with the result
},
),
);
}
// Or use flutter_zxing plugin methods// To read barcode from camera image directlyawait zx.startCameraProcessing(); // Call this in initState
cameraController?.startImageStream((image) async {
finalCode result = await zx.processCameraImage(
image,
DecodeParams(
imageFormat: ImageFormat.lum, // the luminance plane of a YUV420/NV21 frame
format: Format.any,
width: image.width,
height: image.height,
),
);
if (result.isValid) {
debugPrint(result.text);
}
});
zx.stopCameraProcessing(); // Call this in dispose// To read a barcode from an XFile, a path, a URL or raw bytes.// Every method takes a DecodeParams; the defaults are a good starting point.XFile xFile = XFile('Your image path');
Code resultFromXFile = await zx.readBarcodeImagePath(xFile, DecodeParams());
String path = 'Your local image path';
Code resultFromPath = await zx.readBarcodeImagePathString(path, DecodeParams());
String url = 'Your remote image url';
Code resultFromUrl = await zx.readBarcodeImageUrl(url, DecodeParams());
// `readBarcode` is synchronous and takes already-decoded pixels, so the image// dimensions and pixel format have to be described explicitly.Uint8List bytes = Uint8List.fromList(yourImageBytes);
Code resultFromBytes = zx.readBarcode(
bytes,
DecodeParams(imageFormat: ImageFormat.rgb, width: width, height: height),
);
// The reading methods never throw: a failure is reported on the result.if (!resultFromPath.isValid) {
debugPrint(resultFromPath.error);
}
// Every method above has a `readBarcodes...` counterpart that returns `Codes`// with every symbol found in the image.Codes allCodes = await zx.readBarcodesImagePath(xFile, DecodeParams());
To create barcode
import'dart:typed_data';
import'package:flutter_zxing/flutter_zxing.dart';
// Use WriterWidget to quickly create barcode@overrideWidgetbuild(BuildContext context) {
returnScaffold(
body: WriterWidget(
onSuccess: (result, bytes) {
// Do something with the result
},
onError: (error) {
// Do something with the error
},
),
);
}
// Or use FlutterZxing to create barcode directlyfinalEncode result = zx.encodeBarcode(
contents: 'Text to encode',
params: EncodeParams(
format: Format.qrCode,
width: 120,
height: 120,
margin: 10,
eccLevel: EccLevel.low,
),
);
if (result.isValid && result.data != null) {
// `result.data` holds one byte per pixel. Always render it with the size// the encoder reports: when the symbol does not fit the requested box,// zxing enlarges it, so `result.width`/`result.height` may differ from the// width and height that were asked for.finalUint8List encodedBytes = pngFromBytes(
result.data!,
result.width!,
result.height!,
);
// use encodedBytes as you wish, for example Image.memory(encodedBytes)
} else {
debugPrint(result.error);
}