From 363f1d1130d330f5a63dcd61f7f05995ed3a1169 Mon Sep 17 00:00:00 2001 From: Khoren Markosyan Date: Tue, 28 Jun 2022 08:49:03 +0400 Subject: [PATCH] minor changes --- ios/Classes/src/native_zxing.cpp | 14 +++++++------- lib/src/utils/extentions.dart | 10 +++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ios/Classes/src/native_zxing.cpp b/ios/Classes/src/native_zxing.cpp index da1d1cd..858904a 100644 --- a/ios/Classes/src/native_zxing.cpp +++ b/ios/Classes/src/native_zxing.cpp @@ -52,13 +52,13 @@ extern "C" size_t size = (wcslen(resultText) + 1) * sizeof(wchar_t); code.text = new char[size]; std::wcstombs(code.text, resultText, size); - platform_log("zxingRead: %ls", resultText); + platform_log("zxingRead: %ls\n", resultText); } int evalInMillis = static_cast(get_now() - start); if (logEnabled) { - platform_log("zxingRead: %d ms", evalInMillis); + platform_log("zxingRead: %d ms\n", evalInMillis); } return code; } @@ -81,7 +81,7 @@ extern "C" } Results results = ReadBarcodes(image, hints); - auto *codes = new struct CodeResult [results.size()]; + auto *codes = new struct CodeResult[results.size()]; int i = 0; for (auto &result : results) { @@ -96,17 +96,17 @@ extern "C" size_t size = (wcslen(resultText) + 1) * sizeof(wchar_t); code.text = new char[size]; std::wcstombs(code.text, resultText, size); - + codes[i] = code; i++; - platform_log("zxingRead: %s", code.text); + platform_log("zxingRead: %s\n", code.text); } } int evalInMillis = static_cast(get_now() - start); if (logEnabled) { - platform_log("zxingRead: %d ms", evalInMillis); + platform_log("zxingRead: %d ms\n", evalInMillis); } return {i, codes}; } @@ -138,7 +138,7 @@ extern "C" int evalInMillis = static_cast(get_now() - start); if (logEnabled) { - platform_log("zxingEncode: %d ms", evalInMillis); + platform_log("zxingEncode: %d ms\n", evalInMillis); } return result; } diff --git a/lib/src/utils/extentions.dart b/lib/src/utils/extentions.dart index 00b018c..d840544 100644 --- a/lib/src/utils/extentions.dart +++ b/lib/src/utils/extentions.dart @@ -2,6 +2,7 @@ import 'dart:ffi'; import 'dart:typed_data'; import 'package:ffi/ffi.dart'; +import 'package:flutter/foundation.dart'; import '../../flutter_zxing.dart'; @@ -27,7 +28,14 @@ extension EncodeExt on EncodeResult { String? get textString => text == nullptr ? null : text.cast().toDartString(); String get formatString => barcodeFormatName(format); - Uint32List get bytes => data.cast().asTypedList(length); + Uint32List get bytes { + final Pointer ptr = data.cast(); + final Uint32List bytes = ptr.asTypedList(length); + // TODO: Crashes when trying to use 'bytes'. Only on iOS device. Need help to fix. + debugPrint(bytes.toString()); + return bytes; + } + String get errorMessage => error.cast().toDartString(); }