From 58adb27e10daf270c91afbf56678ab045da5fab7 Mon Sep 17 00:00:00 2001 From: Khoren Markosyan Date: Thu, 9 Jun 2022 13:29:42 +0400 Subject: [PATCH] fixed setLogEnabled function issue --- example/lib/main.dart | 3 +- example/pubspec.lock | 2 +- ios/Classes/src/native_zxing.cpp | 14 ++++- ios/Classes/src/native_zxing.h | 13 +++- lib/flutter_zxing.dart | 24 +++----- lib/generated_bindings.dart | 37 +++++++----- .../ios/Runner.xcodeproj/project.pbxproj | 12 ++-- zxscanner/ios/Runner/Info-Debug.plist | 59 +++++++++++++++++++ .../Runner/{Info.plist => Info-Release.plist} | 0 zxscanner/lib/main.dart | 3 + zxscanner/pubspec.lock | 4 +- zxscanner/pubspec.yaml | 2 +- 12 files changed, 127 insertions(+), 46 deletions(-) create mode 100644 zxscanner/ios/Runner/Info-Debug.plist rename zxscanner/ios/Runner/{Info.plist => Info-Release.plist} (100%) diff --git a/example/lib/main.dart b/example/lib/main.dart index 9516e8e..7b54d4c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,9 +1,11 @@ import 'dart:typed_data'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_zxing/flutter_zxing.dart'; void main() { + FlutterZxing.setLogEnabled(kDebugMode); runApp(const MyApp()); } @@ -17,7 +19,6 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { @override Widget build(BuildContext context) { - FlutterZxing.setLogEnabled(true); return const MaterialApp( title: 'Flutter Zxing Example', home: DemoPage(), diff --git a/example/pubspec.lock b/example/pubspec.lock index 1c7ba1a..6496a23 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -141,7 +141,7 @@ packages: path: ".." relative: true source: path - version: "0.3.0" + version: "0.3.1" font_awesome_flutter: dependency: "direct main" description: diff --git a/ios/Classes/src/native_zxing.cpp b/ios/Classes/src/native_zxing.cpp index 6e1e9ca..32cdf7d 100644 --- a/ios/Classes/src/native_zxing.cpp +++ b/ios/Classes/src/native_zxing.cpp @@ -9,6 +9,14 @@ using namespace ZXing; extern "C" { + bool logEnabled = false; + + FUNCTION_ATTRIBUTE + void setLogEnabled(int enabled) + { + logEnabled = enabled; + } + FUNCTION_ATTRIBUTE char const *version() { @@ -16,7 +24,7 @@ extern "C" } FUNCTION_ATTRIBUTE - struct CodeResult readBarcode(char *bytes, int format, int width, int height, int cropWidth, int cropHeight, int logEnabled) + struct CodeResult readBarcode(char *bytes, int format, int width, int height, int cropWidth, int cropHeight) { long long start = get_now(); @@ -55,7 +63,7 @@ extern "C" } FUNCTION_ATTRIBUTE - struct CodeResults 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) { long long start = get_now(); @@ -102,7 +110,7 @@ extern "C" } FUNCTION_ATTRIBUTE - struct EncodeResult encodeBarcode(char *contents, int width, int height, int format, int margin, int eccLevel, int logEnabled) + struct EncodeResult encodeBarcode(char *contents, int width, int height, int format, int margin, int eccLevel) { long long start = get_now(); diff --git a/ios/Classes/src/native_zxing.h b/ios/Classes/src/native_zxing.h index 4b8b8d7..d39f001 100644 --- a/ios/Classes/src/native_zxing.h +++ b/ios/Classes/src/native_zxing.h @@ -51,6 +51,13 @@ extern "C" char *error; }; + /** + * @brief Enables or disables the logging of the library. + * + * @param enabled + */ + void setLogEnabled(int enabled); + /** * Returns the version of the zxing-cpp library. * @@ -69,7 +76,7 @@ extern "C" * @param logEnabled Log enabled. * @return Barcode result. */ - struct CodeResult readBarcode(char *bytes, int format, int width, int height, int cropWidth, int cropHeight, int logEnabled); + struct CodeResult readBarcode(char *bytes, int format, int width, int height, int cropWidth, int cropHeight); /** * @brief Reads barcodes from image. @@ -82,7 +89,7 @@ extern "C" * @param logEnabled Log enabled. * @return Barcode results. */ - struct CodeResults 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); /** * @brief Encode a string into a barcode @@ -95,7 +102,7 @@ extern "C" * @param eccLevel The error correction level of the barcode. Used for Aztec, PDF417, and QRCode only, [0-8]. * @return The barcode data */ - struct EncodeResult encodeBarcode(char *contents, int width, int height, int format, int margin, int eccLevel, int logEnabled); + struct EncodeResult encodeBarcode(char *contents, int width, int height, int format, int margin, int eccLevel); #ifdef __cplusplus } diff --git a/lib/flutter_zxing.dart b/lib/flutter_zxing.dart index 654f544..1f9d131 100644 --- a/lib/flutter_zxing.dart +++ b/lib/flutter_zxing.dart @@ -31,11 +31,9 @@ class FlutterZxing { static IsolateUtils? isolateUtils; - static bool logEnabled = false; - - static void setLogEnabled(bool enabled) { - logEnabled = enabled; - } + /// Enables or disables the logging of the library + static void setLogEnabled(bool enabled) => + bindings.setLogEnabled(enabled ? 1 : 0); /// Returns a version of the zxing library static String version() => bindings.version().cast().toDartString(); @@ -48,7 +46,7 @@ class FlutterZxing { } /// Stops reading barcode from the camera - static stopCameraProcessing() => isolateUtils?.stopReadingBarcode(); + static void stopCameraProcessing() => isolateUtils?.stopReadingBarcode(); /// Reads barcode from String image path static Future readImagePathString( @@ -109,14 +107,14 @@ class FlutterZxing { static CodeResult readBarcode(Uint8List bytes, int format, int width, int height, int cropWidth, int cropHeight) { - return bindings.readBarcode(bytes.allocatePointer(), format, width, height, - cropWidth, cropHeight, _logEnabled); + return bindings.readBarcode( + bytes.allocatePointer(), format, width, height, cropWidth, cropHeight); } static List readBarcodes(Uint8List bytes, int format, int width, int height, int cropWidth, int cropHeight) { - final result = bindings.readBarcodes(bytes.allocatePointer(), format, width, - height, cropWidth, cropHeight, _logEnabled); + final result = bindings.readBarcodes( + bytes.allocatePointer(), format, width, height, cropWidth, cropHeight); List results = []; for (int i = 0; i < result.count; i++) { results.add(result.results.elementAt(i).ref); @@ -127,7 +125,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(), - width, height, format, margin, eccLevel, _logEnabled); + width, height, format, margin, eccLevel); return result; } @@ -147,10 +145,6 @@ class FlutterZxing { return results; } - static int get _logEnabled { - return logEnabled ? 1 : 0; - } - static String formatName(int format) => _formatNames[format] ?? 'Unknown'; } diff --git a/lib/generated_bindings.dart b/lib/generated_bindings.dart index fe8f3be..b872449 100644 --- a/lib/generated_bindings.dart +++ b/lib/generated_bindings.dart @@ -19,6 +19,22 @@ class GeneratedBindings { lookup) : _lookup = lookup; + /// @brief Enables or disables the logging of the library. + /// + /// @param enabled + void setLogEnabled( + int enabled, + ) { + return _setLogEnabled( + enabled, + ); + } + + late final _setLogEnabledPtr = + _lookup>('setLogEnabled'); + late final _setLogEnabled = + _setLogEnabledPtr.asFunction(); + /// Returns the version of the zxing-cpp library. /// /// @return The version of the zxing-cpp library. @@ -47,7 +63,6 @@ class GeneratedBindings { int height, int cropWidth, int cropHeight, - int logEnabled, ) { return _readBarcode( bytes, @@ -56,17 +71,15 @@ class GeneratedBindings { height, cropWidth, cropHeight, - logEnabled, ); } late final _readBarcodePtr = _lookup< ffi.NativeFunction< CodeResult Function(ffi.Pointer, ffi.Int, ffi.Int, ffi.Int, - ffi.Int, ffi.Int, ffi.Int)>>('readBarcode'); + ffi.Int, ffi.Int)>>('readBarcode'); late final _readBarcode = _readBarcodePtr.asFunction< - CodeResult Function( - ffi.Pointer, int, int, int, int, int, int)>(); + CodeResult Function(ffi.Pointer, int, int, int, int, int)>(); /// @brief Reads barcodes from image. /// @param bytes Image bytes. @@ -84,7 +97,6 @@ class GeneratedBindings { int height, int cropWidth, int cropHeight, - int logEnabled, ) { return _readBarcodes( bytes, @@ -93,17 +105,15 @@ class GeneratedBindings { height, cropWidth, cropHeight, - logEnabled, ); } late final _readBarcodesPtr = _lookup< ffi.NativeFunction< CodeResults Function(ffi.Pointer, ffi.Int, ffi.Int, ffi.Int, - ffi.Int, ffi.Int, ffi.Int)>>('readBarcodes'); + ffi.Int, ffi.Int)>>('readBarcodes'); late final _readBarcodes = _readBarcodesPtr.asFunction< - CodeResults Function( - ffi.Pointer, int, int, int, int, int, int)>(); + CodeResults Function(ffi.Pointer, int, int, int, int, int)>(); /// @brief Encode a string into a barcode /// @param contents The string to encode @@ -121,7 +131,6 @@ class GeneratedBindings { int format, int margin, int eccLevel, - int logEnabled, ) { return _encodeBarcode( contents, @@ -130,17 +139,15 @@ class GeneratedBindings { format, margin, eccLevel, - logEnabled, ); } late final _encodeBarcodePtr = _lookup< ffi.NativeFunction< EncodeResult Function(ffi.Pointer, ffi.Int, ffi.Int, - ffi.Int, ffi.Int, ffi.Int, ffi.Int)>>('encodeBarcode'); + ffi.Int, ffi.Int, ffi.Int)>>('encodeBarcode'); late final _encodeBarcode = _encodeBarcodePtr.asFunction< - EncodeResult Function( - ffi.Pointer, int, int, int, int, int, int)>(); + EncodeResult Function(ffi.Pointer, int, int, int, int, int)>(); } abstract class Format { diff --git a/zxscanner/ios/Runner.xcodeproj/project.pbxproj b/zxscanner/ios/Runner.xcodeproj/project.pbxproj index 25c5bb8..99e5711 100644 --- a/zxscanner/ios/Runner.xcodeproj/project.pbxproj +++ b/zxscanner/ios/Runner.xcodeproj/project.pbxproj @@ -44,8 +44,9 @@ 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; - 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 9A8341A4E573B03B27A71F6D /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; + A0B6EF4E2851EC3C0066415F /* Info-Debug.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Debug.plist"; sourceTree = ""; }; + A0B6EF4F2851EC3C0066415F /* Info-Release.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Release.plist"; sourceTree = ""; }; F18E6CF31C3C93655BF7C27D /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -97,9 +98,10 @@ 97C146FA1CF9000F007C117D /* Main.storyboard */, 97C146FD1CF9000F007C117D /* Assets.xcassets */, 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, - 97C147021CF9000F007C117D /* Info.plist */, 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, + A0B6EF4E2851EC3C0066415F /* Info-Debug.plist */, + A0B6EF4F2851EC3C0066415F /* Info-Release.plist */, 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, ); @@ -357,7 +359,7 @@ CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; DEVELOPMENT_TEAM = RE853S4FBU; ENABLE_BITCODE = NO; - INFOPLIST_FILE = Runner/Info.plist; + INFOPLIST_FILE = "Runner/Info-Release.plist"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -486,7 +488,7 @@ CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; DEVELOPMENT_TEAM = RE853S4FBU; ENABLE_BITCODE = NO; - INFOPLIST_FILE = Runner/Info.plist; + INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -509,7 +511,7 @@ CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; DEVELOPMENT_TEAM = RE853S4FBU; ENABLE_BITCODE = NO; - INFOPLIST_FILE = Runner/Info.plist; + INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/zxscanner/ios/Runner/Info-Debug.plist b/zxscanner/ios/Runner/Info-Debug.plist new file mode 100644 index 0000000..686668a --- /dev/null +++ b/zxscanner/ios/Runner/Info-Debug.plist @@ -0,0 +1,59 @@ + + + + + CADisableMinimumFrameDurationOnPhone + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + ZXScanner + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + zxscanner + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + NSBonjourServices + + _dartobservatory._tcp + + NSPhotoLibraryUsageDescription + $(APP_DISPLAY_NAME) needs photo library access to scan barcodes + NSCameraUsageDescription + $(APP_DISPLAY_NAME) needs camera access to scan barcodes + NSLocalNetworkUsageDescription + Allow Flutter tools on your computer to connect and debug your application + + diff --git a/zxscanner/ios/Runner/Info.plist b/zxscanner/ios/Runner/Info-Release.plist similarity index 100% rename from zxscanner/ios/Runner/Info.plist rename to zxscanner/ios/Runner/Info-Release.plist diff --git a/zxscanner/lib/main.dart b/zxscanner/lib/main.dart index d022dbe..9dbfe5a 100644 --- a/zxscanner/lib/main.dart +++ b/zxscanner/lib/main.dart @@ -1,6 +1,8 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; +import 'package:flutter_zxing/flutter_zxing.dart'; import 'package:zxscanner/configs/constants.dart'; import 'package:zxscanner/utils/db_service.dart'; import 'package:zxscanner/utils/extensions.dart'; @@ -16,6 +18,7 @@ void main() async { WidgetsFlutterBinding.ensureInitialized(); await initializePrefs(); await DbService.instance.initializeApp(); + FlutterZxing.setLogEnabled(kDebugMode); runApp(const MyApp()); } diff --git a/zxscanner/pubspec.lock b/zxscanner/pubspec.lock index 86195a0..e75dcfa 100644 --- a/zxscanner/pubspec.lock +++ b/zxscanner/pubspec.lock @@ -300,7 +300,7 @@ packages: path: ".." relative: true source: path - version: "0.3.0" + version: "0.3.1" font_awesome_flutter: dependency: "direct main" description: @@ -823,7 +823,7 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "6.1.2" + version: "6.1.3" url_launcher_android: dependency: transitive description: diff --git a/zxscanner/pubspec.yaml b/zxscanner/pubspec.yaml index 4af18f9..2e61d09 100644 --- a/zxscanner/pubspec.yaml +++ b/zxscanner/pubspec.yaml @@ -29,7 +29,7 @@ dependencies: path_provider: ^2.0.11 share_plus: ^4.0.7 shared_preferences: ^2.0.15 - url_launcher: ^6.1.2 + url_launcher: ^6.1.3 flutter_intl: main_locale: en_US