From 113c6f2221a0982555fb244ac7111e700eca60eb Mon Sep 17 00:00:00 2001 From: Khoren Markosyan Date: Wed, 11 May 2022 20:22:25 +0400 Subject: [PATCH] update README.md --- README.md | 70 ++++++++++++++++++++++++++++++++++++ lib/flutter_zxing.dart | 2 ++ lib/isolate_utils.dart | 1 - lib/zxing_reader_widget.dart | 1 - 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0926a98..158d931 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,76 @@ A barcode and QR code scanner based on [ZXing C++](https://github.com/nu-book/zxing-cpp) library natively in Flutter with Dart FFI. +## Supported Formats + +| 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 | + +## Getting Started +### To read barcode: +```dart +import 'package:flutter_zxing/flutter_zxing.dart'; + +// Use ZxingReaderWidget to quickly read barcode from camera image +@override +Widget build(BuildContext context) { + return Scaffold( + body: ZxingReaderWidget( + onScan: (result) async { + // Do something with the result + }, + ), + ), +); + +// Or use FlutterZxing to read barcode from camera image directly +cameraController?.startImageStream((img) async { + final bytes = await convertImage(img); + final result = FlutterZxing.readBarcode(bytes, Format.Any, img.width, img.height, 200, 200); + if (result.isValidBool) { + debugPrint(result.textString); + } + return null; +}); +``` + +### To create barcode: +```dart +import 'package:flutter_zxing/flutter_zxing.dart'; +import 'dart:typed_data'; +import 'package:image/image.dart' as imglib; + +// Use ZxingWriterWidget to quickly read barcode from camera image +@override +Widget build(BuildContext context) { + return Scaffold( + body: ZxingWriterWidget( + 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'; +final result = FlutterZxing.encodeBarcode(text, 300, 300, Format.Any, 10, 0); +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 MIT License. See [LICENSE](https://github.com/khoren93/flutter_zxing/blob/master/LICENSE). diff --git a/lib/flutter_zxing.dart b/lib/flutter_zxing.dart index de2c80c..3eab0ca 100644 --- a/lib/flutter_zxing.dart +++ b/lib/flutter_zxing.dart @@ -12,6 +12,8 @@ import 'generated_bindings.dart'; export 'generated_bindings.dart'; export 'zxing_reader_widget.dart'; export 'zxing_writer_widget.dart'; +export 'image_converter.dart'; +export 'scanner_overlay.dart'; class FlutterZxing { static const MethodChannel _channel = MethodChannel('flutter_zxing'); diff --git a/lib/isolate_utils.dart b/lib/isolate_utils.dart index c0c510f..b69ef5f 100644 --- a/lib/isolate_utils.dart +++ b/lib/isolate_utils.dart @@ -4,7 +4,6 @@ import 'dart:math'; import 'package:camera/camera.dart'; import 'flutter_zxing.dart'; -import 'image_converter.dart'; // Inspired from https://github.com/am15h/object_detection_flutter diff --git a/lib/zxing_reader_widget.dart b/lib/zxing_reader_widget.dart index b9eda9d..b9f3bcf 100644 --- a/lib/zxing_reader_widget.dart +++ b/lib/zxing_reader_widget.dart @@ -10,7 +10,6 @@ import 'package:flutter_beep/flutter_beep.dart'; import 'flutter_zxing.dart'; import 'isolate_utils.dart'; -import 'scanner_overlay.dart'; class ZxingReaderWidget extends StatefulWidget { const ZxingReaderWidget({