diff --git a/README.md b/README.md index 9a53a46..ea9af2f 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ A barcode and QR code scanner based on [ZXing C++](https://github.com/nu-book/zxing-cpp) library natively in Flutter with Dart FFI. - ## Demo Screenshots +
@@ -34,6 +34,7 @@ A barcode and QR code scanner based on [ZXing C++](https://github.com/nu-book/zx | | DataBar Expanded | ## Features + - Scan barcode from camera stream, image path or url - Scan multiple barcodes from camera stream, image path or url - Create barcode from text @@ -41,10 +42,13 @@ A barcode and QR code scanner based on [ZXing C++](https://github.com/nu-book/zx - Flashlight and pinch to zoom support ## Todo + - Write tests ## Getting Started -### To read barcode: + +### To read barcode + ```dart import 'package:flutter_zxing/flutter_zxing.dart'; @@ -62,31 +66,34 @@ Widget build(BuildContext context) { // Or use flutter_zxing plugin methods // To read barcode from camera image directly -await startCameraProcessing(); // Call this in initState +await zx.startCameraProcessing(); // Call this in initState + cameraController?.startImageStream((image) async { - CodeResult result = await processCameraImage(image); - if (result.isValidBool) { - debugPrint(result.textString); + Code result = await zx.processCameraImage(image); + if (result.isValid) { + debugPrint(result.text); } return null; }); -stopCameraProcessing(); // Call this in dispose + +zx.stopCameraProcessing(); // Call this in dispose // To read barcode from XFile, String, url or Uint8List bytes XFile xFile = XFile('Your image path'); -CodeResult? resultFromXFile = await readBarcodeImagePath(xFile); +Code? resultFromXFile = await zx.readBarcodeImagePath(xFile); String path = 'Your local image path'; -CodeResult? resultFromPath = await readBarcodeImagePathString(path); +Code? resultFromPath = await zx.readBarcodeImagePathString(path); String url = 'Your remote image url'; -CodeResult? resultFromUrl = await readBarcodeImageUrl(url); +Code? resultFromUrl = await zx.readBarcodeImageUrl(url); Uint8List bytes = Uint8List.fromList(yourImageBytes); -CodeResult? resultFromBytes = await readBarcode(bytes); +Code? resultFromBytes = await zx.readBarcode(bytes); ``` -### To create barcode: +### To create barcode + ```dart import 'package:flutter_zxing/flutter_zxing.dart'; import 'dart:typed_data'; @@ -108,7 +115,7 @@ Widget build(BuildContext context) { ); // Or use FlutterZxing to create barcode directly -final result = encodeBarcode( +final result = zx.encodeBarcode( 'Text to encode', format: Format.QRCode, width: 300, @@ -116,7 +123,7 @@ final result = encodeBarcode( margin: 10, eccLevel: 0, ); -if (result.isValidBool) { +if (result.isValid) { final img = imglib.Image.fromBytes(width, height, result.bytes); final encodedBytes = Uint8List.fromList(imglib.encodeJpg(img)); // use encodedBytes as you wish diff --git a/zxscanner/lib/main.dart b/zxscanner/lib/main.dart index 3a1cdbf..8b4dd26 100644 --- a/zxscanner/lib/main.dart +++ b/zxscanner/lib/main.dart @@ -18,7 +18,7 @@ void main() async { WidgetsFlutterBinding.ensureInitialized(); await initializePrefs(); await DbService.instance.initializeApp(); - setZxingLogEnabled(kDebugMode); + zx.setLogEnabled(kDebugMode); runApp(const MyApp()); } diff --git a/zxscanner/lib/models/code.dart b/zxscanner/lib/models/code.dart index bc3d53d..f5f6b05 100644 --- a/zxscanner/lib/models/code.dart +++ b/zxscanner/lib/models/code.dart @@ -1,4 +1,4 @@ -import 'package:flutter_zxing/flutter_zxing.dart'; +import 'package:flutter_zxing/flutter_zxing.dart' as zxing; import 'package:hive_flutter/hive_flutter.dart'; part 'code.g.dart'; @@ -7,10 +7,10 @@ part 'code.g.dart'; class Code extends HiveObject { Code(); - Code.fromCodeResult(CodeResult result) { - isValid = result.isValidBool; + Code.fromCodeResult(zxing.Code result) { + isValid = result.isValid; format = result.format; - text = result.textString; + text = result.text; } @HiveField(0) bool? isValid; @@ -21,5 +21,5 @@ class Code extends HiveObject { @HiveField(2) String? text; - String get formatName => barcodeFormatName(format ?? 0); + String get formatName => zxing.zx.barcodeFormatName(format ?? 0); } diff --git a/zxscanner/lib/models/encode.dart b/zxscanner/lib/models/encode.dart index 65789a2..a70b999 100644 --- a/zxscanner/lib/models/encode.dart +++ b/zxscanner/lib/models/encode.dart @@ -1,6 +1,6 @@ import 'dart:typed_data'; -import 'package:flutter_zxing/flutter_zxing.dart'; +import 'package:flutter_zxing/flutter_zxing.dart' as zxing; import 'package:hive_flutter/hive_flutter.dart'; part 'encode.g.dart'; @@ -9,10 +9,10 @@ part 'encode.g.dart'; class Encode extends HiveObject { Encode(); - Encode.fromEncodeResult(EncodeResult result, Uint8List? bytes) { - isValid = result.isValidBool; + Encode.fromEncodeResult(zxing.Encode result, Uint8List? bytes) { + isValid = result.isValid; format = result.format; - text = result.textString; + text = result.text; data = bytes; length = result.length; } @@ -31,5 +31,5 @@ class Encode extends HiveObject { @HiveField(4) int? length; - String get formatName => barcodeFormatName(format ?? 0); + String get formatName => zxing.zx.barcodeFormatName(format ?? 0); } diff --git a/zxscanner/lib/pages/creator_page.dart b/zxscanner/lib/pages/creator_page.dart index b370df5..b0ccaa5 100644 --- a/zxscanner/lib/pages/creator_page.dart +++ b/zxscanner/lib/pages/creator_page.dart @@ -7,7 +7,7 @@ import 'package:path_provider/path_provider.dart'; import 'package:share_plus/share_plus.dart'; import '../configs/constants.dart'; -import '../models/encode.dart'; +import '../models/encode.dart' as model; import '../utils/db_service.dart'; import '../utils/extensions.dart'; import '../widgets/common_widgets.dart'; @@ -28,7 +28,7 @@ class _CreatorPageState extends State