Browse Source

minor changes

pull/6/head
Khoren Markosyan 2 years ago
parent
commit
363f1d1130
  1. 12
      ios/Classes/src/native_zxing.cpp
  2. 10
      lib/src/utils/extentions.dart

12
ios/Classes/src/native_zxing.cpp

@ -52,13 +52,13 @@ extern "C"
size_t size = (wcslen(resultText) + 1) * sizeof(wchar_t); size_t size = (wcslen(resultText) + 1) * sizeof(wchar_t);
code.text = new char[size]; code.text = new char[size];
std::wcstombs(code.text, resultText, size); std::wcstombs(code.text, resultText, size);
platform_log("zxingRead: %ls", resultText); platform_log("zxingRead: %ls\n", resultText);
} }
int evalInMillis = static_cast<int>(get_now() - start); int evalInMillis = static_cast<int>(get_now() - start);
if (logEnabled) if (logEnabled)
{ {
platform_log("zxingRead: %d ms", evalInMillis); platform_log("zxingRead: %d ms\n", evalInMillis);
} }
return code; return code;
} }
@ -81,7 +81,7 @@ extern "C"
} }
Results results = ReadBarcodes(image, hints); Results results = ReadBarcodes(image, hints);
auto *codes = new struct CodeResult [results.size()]; auto *codes = new struct CodeResult[results.size()];
int i = 0; int i = 0;
for (auto &result : results) for (auto &result : results)
{ {
@ -99,14 +99,14 @@ extern "C"
codes[i] = code; codes[i] = code;
i++; i++;
platform_log("zxingRead: %s", code.text); platform_log("zxingRead: %s\n", code.text);
} }
} }
int evalInMillis = static_cast<int>(get_now() - start); int evalInMillis = static_cast<int>(get_now() - start);
if (logEnabled) if (logEnabled)
{ {
platform_log("zxingRead: %d ms", evalInMillis); platform_log("zxingRead: %d ms\n", evalInMillis);
} }
return {i, codes}; return {i, codes};
} }
@ -138,7 +138,7 @@ extern "C"
int evalInMillis = static_cast<int>(get_now() - start); int evalInMillis = static_cast<int>(get_now() - start);
if (logEnabled) if (logEnabled)
{ {
platform_log("zxingEncode: %d ms", evalInMillis); platform_log("zxingEncode: %d ms\n", evalInMillis);
} }
return result; return result;
} }

10
lib/src/utils/extentions.dart

@ -2,6 +2,7 @@ import 'dart:ffi';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:ffi/ffi.dart'; import 'package:ffi/ffi.dart';
import 'package:flutter/foundation.dart';
import '../../flutter_zxing.dart'; import '../../flutter_zxing.dart';
@ -27,7 +28,14 @@ extension EncodeExt on EncodeResult {
String? get textString => String? get textString =>
text == nullptr ? null : text.cast<Utf8>().toDartString(); text == nullptr ? null : text.cast<Utf8>().toDartString();
String get formatString => barcodeFormatName(format); String get formatString => barcodeFormatName(format);
Uint32List get bytes => data.cast<Uint32>().asTypedList(length); Uint32List get bytes {
final Pointer<Uint32> ptr = data.cast<Uint32>();
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<Utf8>().toDartString(); String get errorMessage => error.cast<Utf8>().toDartString();
} }

Loading…
Cancel
Save