diff --git a/ios/Classes/src/native_zxing.cpp b/ios/Classes/src/native_zxing.cpp index bb53e83..6e1e9ca 100644 --- a/ios/Classes/src/native_zxing.cpp +++ b/ios/Classes/src/native_zxing.cpp @@ -55,7 +55,7 @@ extern "C" } FUNCTION_ATTRIBUTE - struct CodeResult* readBarcodes(char *bytes, int format, int width, int height, int cropWidth, int cropHeight, int logEnabled) + struct CodeResults readBarcodes(char *bytes, int format, int width, int height, int cropWidth, int cropHeight, int logEnabled) { long long start = get_now(); @@ -98,7 +98,7 @@ extern "C" { platform_log("zxingRead: %d ms", evalInMillis); } - return codes; + return {i, codes}; } FUNCTION_ATTRIBUTE diff --git a/ios/Classes/src/native_zxing.h b/ios/Classes/src/native_zxing.h index 000b67a..4b8b8d7 100644 --- a/ios/Classes/src/native_zxing.h +++ b/ios/Classes/src/native_zxing.h @@ -35,6 +35,12 @@ extern "C" enum Format format; }; + struct CodeResults + { + int count; + struct CodeResult* results; + }; + struct EncodeResult { int isValid; @@ -76,7 +82,7 @@ extern "C" * @param logEnabled Log enabled. * @return Barcode results. */ - struct CodeResult* readBarcodes(char *bytes, int format, int width, int height, int cropWidth, int cropHeight, int logEnabled); + struct CodeResults readBarcodes(char *bytes, int format, int width, int height, int cropWidth, int cropHeight, int logEnabled); /** * @brief Encode a string into a barcode diff --git a/lib/flutter_zxing.dart b/lib/flutter_zxing.dart index 482cc53..654f544 100644 --- a/lib/flutter_zxing.dart +++ b/lib/flutter_zxing.dart @@ -6,7 +6,6 @@ import 'dart:typed_data'; import 'package:camera/camera.dart'; import 'package:ffi/ffi.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:image/image.dart' as imglib; @@ -118,8 +117,11 @@ class FlutterZxing { int height, int cropWidth, int cropHeight) { final result = bindings.readBarcodes(bytes.allocatePointer(), format, width, height, cropWidth, cropHeight, _logEnabled); - debugPrint(result.toString()); - return []; + List results = []; + for (int i = 0; i < result.count; i++) { + results.add(result.results.elementAt(i).ref); + } + return results; } static EncodeResult encodeBarcode(String contents, int width, int height, diff --git a/lib/generated_bindings.dart b/lib/generated_bindings.dart index 6df0193..fe8f3be 100644 --- a/lib/generated_bindings.dart +++ b/lib/generated_bindings.dart @@ -77,7 +77,7 @@ class GeneratedBindings { /// @param cropHeight Crop height. /// @param logEnabled Log enabled. /// @return Barcode results. - ffi.Pointer readBarcodes( + CodeResults readBarcodes( ffi.Pointer bytes, int format, int width, @@ -99,10 +99,10 @@ class GeneratedBindings { late final _readBarcodesPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer, ffi.Int, - ffi.Int, ffi.Int, ffi.Int, ffi.Int, ffi.Int)>>('readBarcodes'); + CodeResults Function(ffi.Pointer, ffi.Int, ffi.Int, ffi.Int, + ffi.Int, ffi.Int, ffi.Int)>>('readBarcodes'); late final _readBarcodes = _readBarcodesPtr.asFunction< - ffi.Pointer Function( + CodeResults Function( ffi.Pointer, int, int, int, int, int, int)>(); /// @brief Encode a string into a barcode @@ -209,6 +209,13 @@ class CodeResult extends ffi.Struct { external int format; } +class CodeResults extends ffi.Struct { + @ffi.Int() + external int count; + + external ffi.Pointer results; +} + class EncodeResult extends ffi.Struct { @ffi.Int() external int isValid;