Browse Source

fixed setLogEnabled function issue

pull/3/head
Khoren Markosyan 3 years ago
parent
commit
58adb27e10
  1. 3
      example/lib/main.dart
  2. 2
      example/pubspec.lock
  3. 14
      ios/Classes/src/native_zxing.cpp
  4. 13
      ios/Classes/src/native_zxing.h
  5. 24
      lib/flutter_zxing.dart
  6. 37
      lib/generated_bindings.dart
  7. 12
      zxscanner/ios/Runner.xcodeproj/project.pbxproj
  8. 59
      zxscanner/ios/Runner/Info-Debug.plist
  9. 0
      zxscanner/ios/Runner/Info-Release.plist
  10. 3
      zxscanner/lib/main.dart
  11. 4
      zxscanner/pubspec.lock
  12. 2
      zxscanner/pubspec.yaml

3
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<MyApp> {
@override
Widget build(BuildContext context) {
FlutterZxing.setLogEnabled(true);
return const MaterialApp(
title: 'Flutter Zxing Example',
home: DemoPage(),

2
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:

14
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();

13
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
}

24
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<Utf8>().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<CodeResult?> 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<CodeResult> 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<CodeResult> 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<Char>(),
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';
}

37
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<ffi.NativeFunction<ffi.Void Function(ffi.Int)>>('setLogEnabled');
late final _setLogEnabled =
_setLogEnabledPtr.asFunction<void Function(int)>();
/// 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.Char>, 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<ffi.Char>, int, int, int, int, int, int)>();
CodeResult Function(ffi.Pointer<ffi.Char>, 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.Char>, 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<ffi.Char>, int, int, int, int, int, int)>();
CodeResults Function(ffi.Pointer<ffi.Char>, 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.Char>, 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<ffi.Char>, int, int, int, int, int, int)>();
EncodeResult Function(ffi.Pointer<ffi.Char>, int, int, int, int, int)>();
}
abstract class Format {

12
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 = "<group>"; };
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
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 = "<group>"; };
A0B6EF4E2851EC3C0066415F /* Info-Debug.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Debug.plist"; sourceTree = "<group>"; };
A0B6EF4F2851EC3C0066415F /* Info-Release.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Release.plist"; sourceTree = "<group>"; };
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 = "<group>"; };
/* 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",

59
zxscanner/ios/Runner/Info-Debug.plist

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>ZXScanner</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>zxscanner</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSBonjourServices</key>
<array>
<string>_dartobservatory._tcp</string>
</array>
<key>NSPhotoLibraryUsageDescription</key>
<string>$(APP_DISPLAY_NAME) needs photo library access to scan barcodes</string>
<key>NSCameraUsageDescription</key>
<string>$(APP_DISPLAY_NAME) needs camera access to scan barcodes</string>
<key>NSLocalNetworkUsageDescription</key>
<string>Allow Flutter tools on your computer to connect and debug your application</string>
</dict>
</plist>

0
zxscanner/ios/Runner/Info.plist → zxscanner/ios/Runner/Info-Release.plist

3
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());
}

4
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:

2
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

Loading…
Cancel
Save