diff --git a/example/pubspec.lock b/example/pubspec.lock index 04054b6..1c7ba1a 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -141,7 +141,7 @@ packages: path: ".." relative: true source: path - version: "0.2.0" + version: "0.3.0" font_awesome_flutter: dependency: "direct main" description: diff --git a/ios/Classes/src/native_zxing.cpp b/ios/Classes/src/native_zxing.cpp index 0984ed7..bb53e83 100644 --- a/ios/Classes/src/native_zxing.cpp +++ b/ios/Classes/src/native_zxing.cpp @@ -24,7 +24,7 @@ extern "C" auto *data = new uint8_t[length]; memcpy(data, bytes, length); - BarcodeFormats formats = BarcodeFormat(format); // BarcodeFormat::Any; + BarcodeFormats formats = BarcodeFormat(format); DecodeHints hints = DecodeHints().setTryHarder(false).setTryRotate(true).setFormats(formats); ImageView image{data, width, height, ImageFormat::Lum}; if (cropWidth > 0 && cropHeight > 0 && cropWidth < width && cropHeight < height) @@ -37,10 +37,13 @@ extern "C" if (result.isValid()) { code.isValid = result.isValid(); - code.text = new char[result.text().length() + 1]; - std::string text = std::string(result.text().begin(), result.text().end()); - strcpy(code.text, text.c_str()); + code.format = Format(static_cast(result.format())); + + const wchar_t *resultText = result.text().c_str(); + size_t size = (wcslen(resultText) + 1) * sizeof(wchar_t); + code.text = new char[size]; + std::wcstombs(code.text, resultText, size); } int evalInMillis = static_cast(get_now() - start); @@ -60,7 +63,7 @@ extern "C" auto *data = new uint8_t[length]; memcpy(data, bytes, length); - BarcodeFormats formats = BarcodeFormat(format); // BarcodeFormat::Any; + BarcodeFormats formats = BarcodeFormat(format); DecodeHints hints = DecodeHints().setTryHarder(false).setTryRotate(true).setFormats(formats); ImageView image{data, width, height, ImageFormat::Lum}; if (cropWidth > 0 && cropHeight > 0 && cropWidth < width && cropHeight < height) @@ -77,10 +80,14 @@ extern "C" if (result.isValid()) { code.isValid = result.isValid(); - code.text = new char[result.text().length() + 1]; - std::string text = std::string(result.text().begin(), result.text().end()); - strcpy(code.text, text.c_str()); + code.format = Format(static_cast(result.format())); + + const wchar_t *resultText = result.text().c_str(); + size_t size = (wcslen(resultText) + 1) * sizeof(wchar_t); + code.text = new char[size]; + std::wcstombs(code.text, resultText, size); + codes[i] = code; i++; } diff --git a/lib/flutter_zxing.dart b/lib/flutter_zxing.dart index 950f29c..482cc53 100644 --- a/lib/flutter_zxing.dart +++ b/lib/flutter_zxing.dart @@ -124,7 +124,7 @@ class FlutterZxing { static EncodeResult encodeBarcode(String contents, int width, int height, int format, int margin, int eccLevel) { - var result = bindings.encodeBarcode(contents.toNativeUtf8().cast(), + var result = bindings.encodeBarcode(contents.toNativeUtf8().cast(), width, height, format, margin, eccLevel, _logEnabled); return result; } @@ -166,11 +166,11 @@ DynamicLibrary dylib = _openDynamicLibrary(); extension Uint8ListBlobConversion on Uint8List { /// Allocates a pointer filled with the Uint8List data. - Pointer allocatePointer() { + Pointer allocatePointer() { final blob = calloc(length); final blobBytes = blob.asTypedList(length); blobBytes.setAll(0, this); - return blob; + return blob.cast(); } } @@ -186,7 +186,7 @@ extension EncodeExt on EncodeResult { String? get textString => text == nullptr ? null : text.cast().toDartString(); String get formatString => FlutterZxing.formatName(format); - Uint32List get bytes => data.asTypedList(length); + Uint32List get bytes => data.cast().asTypedList(length); String get errorMessage => error.cast().toDartString(); } diff --git a/lib/generated_bindings.dart b/lib/generated_bindings.dart index d5778ab..6df0193 100644 --- a/lib/generated_bindings.dart +++ b/lib/generated_bindings.dart @@ -22,14 +22,14 @@ class GeneratedBindings { /// Returns the version of the zxing-cpp library. /// /// @return The version of the zxing-cpp library. - ffi.Pointer version() { + ffi.Pointer version() { return _version(); } late final _versionPtr = - _lookup Function()>>('version'); + _lookup Function()>>('version'); late final _version = - _versionPtr.asFunction Function()>(); + _versionPtr.asFunction Function()>(); /// @brief Reads barcode from image. /// @param bytes Image bytes. @@ -41,7 +41,7 @@ class GeneratedBindings { /// @param logEnabled Log enabled. /// @return Barcode result. CodeResult readBarcode( - ffi.Pointer bytes, + ffi.Pointer bytes, int format, int width, int height, @@ -62,11 +62,11 @@ class GeneratedBindings { late final _readBarcodePtr = _lookup< ffi.NativeFunction< - CodeResult Function(ffi.Pointer, ffi.Int32, ffi.Int32, - ffi.Int32, ffi.Int32, ffi.Int32, ffi.Int32)>>('readBarcode'); + CodeResult Function(ffi.Pointer, ffi.Int, ffi.Int, ffi.Int, + ffi.Int, ffi.Int, ffi.Int)>>('readBarcode'); late final _readBarcode = _readBarcodePtr.asFunction< CodeResult Function( - ffi.Pointer, int, int, int, int, int, int)>(); + ffi.Pointer, int, int, int, int, int, int)>(); /// @brief Reads barcodes from image. /// @param bytes Image bytes. @@ -78,7 +78,7 @@ class GeneratedBindings { /// @param logEnabled Log enabled. /// @return Barcode results. ffi.Pointer readBarcodes( - ffi.Pointer bytes, + ffi.Pointer bytes, int format, int width, int height, @@ -99,17 +99,11 @@ class GeneratedBindings { late final _readBarcodesPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Int32, - ffi.Int32, - ffi.Int32, - ffi.Int32, - ffi.Int32, - ffi.Int32)>>('readBarcodes'); + ffi.Pointer Function(ffi.Pointer, ffi.Int, + ffi.Int, ffi.Int, ffi.Int, ffi.Int, ffi.Int)>>('readBarcodes'); late final _readBarcodes = _readBarcodesPtr.asFunction< ffi.Pointer Function( - ffi.Pointer, int, int, int, int, int, int)>(); + ffi.Pointer, int, int, int, int, int, int)>(); /// @brief Encode a string into a barcode /// @param contents The string to encode @@ -121,7 +115,7 @@ class GeneratedBindings { /// @param eccLevel The error correction level of the barcode. Used for Aztec, PDF417, and QRCode only, [0-8]. /// @return The barcode data EncodeResult encodeBarcode( - ffi.Pointer contents, + ffi.Pointer contents, int width, int height, int format, @@ -142,11 +136,11 @@ class GeneratedBindings { late final _encodeBarcodePtr = _lookup< ffi.NativeFunction< - EncodeResult Function(ffi.Pointer, ffi.Int32, ffi.Int32, - ffi.Int32, ffi.Int32, ffi.Int32, ffi.Int32)>>('encodeBarcode'); + EncodeResult Function(ffi.Pointer, ffi.Int, ffi.Int, + ffi.Int, ffi.Int, ffi.Int, ffi.Int)>>('encodeBarcode'); late final _encodeBarcode = _encodeBarcodePtr.asFunction< EncodeResult Function( - ffi.Pointer, int, int, int, int, int, int)>(); + ffi.Pointer, int, int, int, int, int, int)>(); } abstract class Format { @@ -206,28 +200,28 @@ abstract class Format { } class CodeResult extends ffi.Struct { - @ffi.Int32() + @ffi.Int() external int isValid; - external ffi.Pointer text; + external ffi.Pointer text; @ffi.Int32() external int format; } class EncodeResult extends ffi.Struct { - @ffi.Int32() + @ffi.Int() external int isValid; - external ffi.Pointer text; + external ffi.Pointer text; @ffi.Int32() external int format; - external ffi.Pointer data; + external ffi.Pointer data; - @ffi.Int32() + @ffi.Int() external int length; - external ffi.Pointer error; + external ffi.Pointer error; } diff --git a/lib/reader_widget.dart b/lib/reader_widget.dart index b182939..9b6e40c 100644 --- a/lib/reader_widget.dart +++ b/lib/reader_widget.dart @@ -89,6 +89,8 @@ class _ReaderWidgetState extends State } if (mounted) { if (message == AppLifecycleState.paused.toString()) { + await cameraController.stopImageStream(); + await cameraController.dispose(); _cameraOn = false; setState(() {}); } diff --git a/zxscanner/pubspec.lock b/zxscanner/pubspec.lock index 391758a..86195a0 100644 --- a/zxscanner/pubspec.lock +++ b/zxscanner/pubspec.lock @@ -300,7 +300,7 @@ packages: path: ".." relative: true source: path - version: "0.2.0" + version: "0.3.0" font_awesome_flutter: dependency: "direct main" description: @@ -524,7 +524,7 @@ packages: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "2.0.10" + version: "2.0.11" path_provider_android: dependency: transitive description: diff --git a/zxscanner/pubspec.yaml b/zxscanner/pubspec.yaml index 68e3b9c..4af18f9 100644 --- a/zxscanner/pubspec.yaml +++ b/zxscanner/pubspec.yaml @@ -26,7 +26,7 @@ dependencies: image_picker: ^0.8.5 intl: ^0.17.0 mobx: ^2.0.7 - path_provider: ^2.0.10 + path_provider: ^2.0.11 share_plus: ^4.0.7 shared_preferences: ^2.0.15 url_launcher: ^6.1.2