diff --git a/example/pubspec.lock b/example/pubspec.lock index 6a34d75..8f91a5e 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -28,7 +28,7 @@ packages: name: camera url: "https://pub.dartlang.org" source: hosted - version: "0.9.5+1" + version: "0.9.7" camera_platform_interface: dependency: transitive description: @@ -77,7 +77,7 @@ packages: name: cross_file url: "https://pub.dartlang.org" source: hosted - version: "0.3.3" + version: "0.3.3+1" crypto: dependency: transitive description: @@ -162,14 +162,14 @@ packages: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.0.1" image: dependency: "direct main" description: name: image url: "https://pub.dartlang.org" source: hosted - version: "3.1.3" + version: "3.2.0" image_picker: dependency: "direct main" description: @@ -197,7 +197,7 @@ packages: name: image_picker_ios url: "https://pub.dartlang.org" source: hosted - version: "0.8.5+4" + version: "0.8.5+5" image_picker_platform_interface: dependency: transitive description: @@ -342,7 +342,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "5.4.1" + version: "6.1.0" sdks: dart: ">=2.17.0 <3.0.0" flutter: ">=2.8.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 005b100..858c4ff 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: flutter_zxing: path: ../ font_awesome_flutter: ^10.1.0 - image: ^3.1.3 + image: ^3.2.0 image_picker: ^0.8.5 dev_dependencies: diff --git a/ios/Classes/src/native_zxing.cpp b/ios/Classes/src/native_zxing.cpp index fca7183..0984ed7 100644 --- a/ios/Classes/src/native_zxing.cpp +++ b/ios/Classes/src/native_zxing.cpp @@ -102,7 +102,7 @@ extern "C" struct EncodeResult result = {0, contents, Format(format), nullptr, 0, nullptr}; try { - auto writer = MultiFormatWriter(BarcodeFormat(format)).setMargin(margin).setEccLevel(eccLevel); + auto writer = MultiFormatWriter(BarcodeFormat(format)).setMargin(margin).setEccLevel(eccLevel).setEncoding(CharacterSet::UTF8); auto bitMatrix = writer.encode(TextUtfEncoding::FromUtf8(std::string(contents)), width, height); result.data = ToMatrix(bitMatrix).data(); result.length = bitMatrix.width() * bitMatrix.height(); diff --git a/pubspec.yaml b/pubspec.yaml index 162cc98..17e4144 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,12 +8,12 @@ environment: flutter: ">=2.5.0" dependencies: - camera: ^0.9.5 + camera: ^0.9.7 ffi: ^1.2.1 flutter: sdk: flutter flutter_beep: ^1.0.0 - image: ^3.1.3 + image: ^3.2.0 dev_dependencies: ffigen: ^5.0.0 # dart run ffigen diff --git a/zxscanner/lib/configs/app_store.dart b/zxscanner/lib/configs/app_store.dart index 60187cd..dd6c6d1 100644 --- a/zxscanner/lib/configs/app_store.dart +++ b/zxscanner/lib/configs/app_store.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:mobx/mobx.dart'; -import 'package:nb_utils/nb_utils.dart'; +import 'package:zxscanner/utils/shared_pref.dart'; part 'app_store.g.dart'; @@ -33,30 +33,30 @@ abstract class AppStoreBase with Store { @action Future setThemeMode(ThemeMode value) async { themeMode = value; - setValue(themeModePref, themeMode.toString()); + setPrefValue(themeModePref, themeMode.toString()); } @action Future setColorSchemeIndex(int value) async { colorSchemeIndex = value; - await setValue(colorSchemeIndexPref, colorSchemeIndex); + await setPrefValue(colorSchemeIndexPref, colorSchemeIndex); } @action Future toggleSoundMode({bool? value}) async { isSoundOn = value ?? !isSoundOn; - setValue(isSoundOnPref, isSoundOn); + setPrefValue(isSoundOnPref, isSoundOn); } @action Future toggleVibrationMode({bool? value}) async { isVibrationOn = value ?? !isVibrationOn; - setValue(isVibrationOnPref, isVibrationOn); + setPrefValue(isVibrationOnPref, isVibrationOn); } @action Future setLanguage(String aLanguage) async { selectedLanguage = aLanguage; - await setValue(languagePref, aLanguage); + await setPrefValue(languagePref, aLanguage); } } diff --git a/zxscanner/lib/main.dart b/zxscanner/lib/main.dart index e266f4a..d022dbe 100644 --- a/zxscanner/lib/main.dart +++ b/zxscanner/lib/main.dart @@ -4,7 +4,7 @@ import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:zxscanner/configs/constants.dart'; import 'package:zxscanner/utils/db_service.dart'; import 'package:zxscanner/utils/extensions.dart'; -import 'package:nb_utils/nb_utils.dart'; +import 'package:zxscanner/utils/shared_pref.dart'; import 'configs/app_store.dart'; import 'configs/app_theme.dart'; @@ -14,36 +14,11 @@ import 'utils/scroll_behavior.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); - await _initializeAppStore(); + await initializePrefs(); await DbService.instance.initializeApp(); runApp(const MyApp()); } -_initializeAppStore() async { - await initialize(); - final themeModeString = getStringAsync( - themeModePref, - defaultValue: appStore.themeMode.toString(), - ); - await appStore.setThemeMode( - ThemeMode.values - .firstWhere((element) => element.toString() == themeModeString), - ); - await appStore.setColorSchemeIndex( - getIntAsync(colorSchemeIndexPref, defaultValue: appStore.colorSchemeIndex), - ); - await appStore.toggleSoundMode( - value: getBoolAsync(isSoundOnPref, defaultValue: appStore.isSoundOn), - ); - await appStore.toggleVibrationMode( - value: - getBoolAsync(isVibrationOnPref, defaultValue: appStore.isVibrationOn), - ); - await appStore.setLanguage( - getStringAsync(languagePref, defaultValue: appStore.selectedLanguage), - ); -} - class MyApp extends StatefulWidget { const MyApp({Key? key}) : super(key: key); diff --git a/zxscanner/lib/pages/barcodes_page.dart b/zxscanner/lib/pages/barcodes_page.dart index b626231..4fb7cfc 100644 --- a/zxscanner/lib/pages/barcodes_page.dart +++ b/zxscanner/lib/pages/barcodes_page.dart @@ -51,34 +51,36 @@ class _BarcodesPageState extends State { itemBuilder: (context, index) { final result = results[index]; return ContainerX( - child: ListTile( - leading: Image.memory( - result.data ?? Uint8List(0), - width: 60, - ), - title: Text(result.text ?? ''), - subtitle: Text(result.formatName), - trailing: ButtonBar( - mainAxisSize: MainAxisSize.min, - children: [ - // Copy button - IconButton( - icon: const Icon(FontAwesomeIcons.copy), - onPressed: () { - Clipboard.setData( - ClipboardData(text: result.text)); - }, - ), - // Remove button - IconButton( - icon: const Icon(FontAwesomeIcons.trash, - color: Colors.red), - onPressed: () { - DbService.instance.deleteEncode(result); - setState(() {}); - }, - ), - ], + child: Card( + child: ListTile( + leading: Image.memory( + result.data ?? Uint8List(0), + width: 60, + ), + title: Text(result.text ?? ''), + subtitle: Text(result.formatName), + trailing: ButtonBar( + mainAxisSize: MainAxisSize.min, + children: [ + // Copy button + IconButton( + icon: const Icon(FontAwesomeIcons.copy), + onPressed: () { + Clipboard.setData( + ClipboardData(text: result.text)); + }, + ), + // Remove button + IconButton( + icon: const Icon(FontAwesomeIcons.trash, + color: Colors.red), + onPressed: () { + DbService.instance.deleteEncode(result); + setState(() {}); + }, + ), + ], + ), ), ), ); diff --git a/zxscanner/lib/pages/help_page.dart b/zxscanner/lib/pages/help_page.dart index d46bf9c..4ed0d85 100644 --- a/zxscanner/lib/pages/help_page.dart +++ b/zxscanner/lib/pages/help_page.dart @@ -5,6 +5,7 @@ import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:flutter_zxing/flutter_zxing.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:image/image.dart' as imglib; +import 'package:url_launcher/url_launcher_string.dart'; import 'package:zxscanner/configs/constants.dart'; import 'package:zxscanner/widgets/common_widgets.dart'; @@ -18,9 +19,30 @@ class HelpPage extends StatelessWidget { title: const Text('Help'), ), body: ContainerX( - child: ListView( - padding: const EdgeInsets.only(bottom: spaceLarge2), - children: createSlides(context), + child: Column( + children: [ + Padding( + padding: const EdgeInsets.all(spaceDefault), + child: InkWell( + onTap: () { + launchUrlString('https://scanbot.io'); + }, + child: Column( + children: const [ + Text('All information is taken from'), + Text('scanbot.io', + style: TextStyle(fontWeight: FontWeight.bold)), + ], + ), + ), + ), + Expanded( + child: ListView( + padding: const EdgeInsets.only(bottom: spaceLarge2), + children: createSlides(context), + ), + ), + ], ), ), ); diff --git a/zxscanner/lib/pages/history_page.dart b/zxscanner/lib/pages/history_page.dart index 1f0eb1f..e9c349b 100644 --- a/zxscanner/lib/pages/history_page.dart +++ b/zxscanner/lib/pages/history_page.dart @@ -42,30 +42,32 @@ class _HistoryPageState extends State { itemBuilder: (context, index) { final result = results[index]; return ContainerX( - child: ListTile( - title: Text(result.text ?? ''), - subtitle: Text(result.formatName), - trailing: ButtonBar( - mainAxisSize: MainAxisSize.min, - children: [ - // Copy button - IconButton( - icon: const Icon(FontAwesomeIcons.copy), - onPressed: () { - Clipboard.setData( - ClipboardData(text: result.text)); - }, - ), - // Remove button - IconButton( - icon: const Icon(FontAwesomeIcons.trash, - color: Colors.red), - onPressed: () { - DbService.instance.deleteCode(result); - setState(() {}); - }, - ), - ], + child: Card( + child: ListTile( + title: Text(result.text ?? ''), + subtitle: Text(result.formatName), + trailing: ButtonBar( + mainAxisSize: MainAxisSize.min, + children: [ + // Copy button + IconButton( + icon: const Icon(FontAwesomeIcons.copy), + onPressed: () { + Clipboard.setData( + ClipboardData(text: result.text)); + }, + ), + // Remove button + IconButton( + icon: const Icon(FontAwesomeIcons.trash, + color: Colors.red), + onPressed: () { + DbService.instance.deleteCode(result); + setState(() {}); + }, + ), + ], + ), ), ), ); diff --git a/zxscanner/lib/utils/shared_pref.dart b/zxscanner/lib/utils/shared_pref.dart new file mode 100644 index 0000000..1a51f02 --- /dev/null +++ b/zxscanner/lib/utils/shared_pref.dart @@ -0,0 +1,100 @@ +import 'dart:convert'; + +import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:zxscanner/configs/app_store.dart'; + +late SharedPreferences sharedPreferences; + +Future initializePrefs() async { + sharedPreferences = await SharedPreferences.getInstance(); + final themeModeString = getPrefString( + themeModePref, + defaultValue: appStore.themeMode.toString(), + ); + await appStore.setThemeMode( + ThemeMode.values + .firstWhere((element) => element.toString() == themeModeString), + ); + await appStore.setColorSchemeIndex( + getPrefInt(colorSchemeIndexPref, defaultValue: appStore.colorSchemeIndex), + ); + await appStore.toggleSoundMode( + value: getPrefBool(isSoundOnPref, defaultValue: appStore.isSoundOn), + ); + await appStore.toggleVibrationMode( + value: getPrefBool(isVibrationOnPref, defaultValue: appStore.isVibrationOn), + ); + await appStore.setLanguage( + getPrefString(languagePref, defaultValue: appStore.selectedLanguage), + ); +} + +/// Add a value in SharedPref based on their type - Must be a String, int, bool, double, Map or StringList +Future setPrefValue(String key, dynamic value, + {bool print = true}) async { + if (value is String) { + return await sharedPreferences.setString(key, value); + } else if (value is int) { + return await sharedPreferences.setInt(key, value); + } else if (value is bool) { + return await sharedPreferences.setBool(key, value); + } else if (value is double) { + return await sharedPreferences.setDouble(key, value); + } else if (value is Map) { + return await sharedPreferences.setString(key, jsonEncode(value)); + } else if (value is List) { + return await sharedPreferences.setStringList(key, value); + } else { + throw ArgumentError( + 'Invalid value ${value.runtimeType} - Must be a String, int, bool, double, Map or StringList'); + } +} + +/// Returns List of Keys that matches with given Key +List getMatchingSharedPrefKeys(String key) { + List keys = []; + sharedPreferences.getKeys().forEach((element) { + if (element.contains(key)) { + keys.add(element); + } + }); + return keys; +} + +/// Returns a StringList if exists in SharedPref +List? getPrefStringList(String key) => + sharedPreferences.getStringList(key); + +/// Returns a Bool if exists in SharedPref +bool getPrefBool(String key, {bool defaultValue = false}) => + sharedPreferences.getBool(key) ?? defaultValue; + +/// Returns a Double if exists in SharedPref +double getPrefDouble(String key, {double defaultValue = 0.0}) => + sharedPreferences.getDouble(key) ?? defaultValue; + +/// Returns a Int if exists in SharedPref +int getPrefInt(String key, {int defaultValue = 0}) => + sharedPreferences.getInt(key) ?? defaultValue; + +/// Returns a String if exists in SharedPref +String getPrefString(String key, {String defaultValue = ''}) => + sharedPreferences.getString(key) ?? defaultValue; + +/// Returns a JSON if exists in SharedPref +Map getPrefJSON(String key, + {Map? defaultValue}) { + if (sharedPreferences.containsKey(key)) { + return jsonDecode(sharedPreferences.getString(key) ?? ''); + } else { + return defaultValue ?? {}; + } +} + +/// remove key from SharedPref +Future removePrefKey(String key) async => + await sharedPreferences.remove(key); + +/// clear SharedPref +Future clearSharedPref() async => await sharedPreferences.clear(); diff --git a/zxscanner/pubspec.lock b/zxscanner/pubspec.lock index bfb4911..0714194 100644 --- a/zxscanner/pubspec.lock +++ b/zxscanner/pubspec.lock @@ -98,14 +98,14 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.3.0" + version: "8.3.2" camera: dependency: transitive description: name: camera url: "https://pub.dartlang.org" source: hosted - version: "0.9.5+1" + version: "0.9.7" camera_platform_interface: dependency: transitive description: @@ -162,48 +162,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.16.0" - connectivity_plus: - dependency: transitive - description: - name: connectivity_plus - url: "https://pub.dartlang.org" - source: hosted - version: "2.3.0" - connectivity_plus_linux: - dependency: transitive - description: - name: connectivity_plus_linux - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" - connectivity_plus_macos: - dependency: transitive - description: - name: connectivity_plus_macos - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.2" - connectivity_plus_platform_interface: - dependency: transitive - description: - name: connectivity_plus_platform_interface - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - connectivity_plus_web: - dependency: transitive - description: - name: connectivity_plus_web - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - connectivity_plus_windows: - dependency: transitive - description: - name: connectivity_plus_windows - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" convert: dependency: transitive description: @@ -224,7 +182,7 @@ packages: name: cross_file url: "https://pub.dartlang.org" source: hosted - version: "0.3.3" + version: "0.3.3+1" crypto: dependency: transitive description: @@ -246,13 +204,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.2.3" - dbus: - dependency: transitive - description: - name: dbus - url: "https://pub.dartlang.org" - source: hosted - version: "0.7.3" fake_async: dependency: transitive description: @@ -318,7 +269,7 @@ packages: name: flutter_markdown url: "https://pub.dartlang.org" source: hosted - version: "0.6.10" + version: "0.6.10+1" flutter_mobx: dependency: "direct main" description: @@ -350,13 +301,6 @@ packages: relative: true source: path version: "0.1.2" - fluttertoast: - dependency: transitive - description: - name: fluttertoast - url: "https://pub.dartlang.org" - source: hosted - version: "8.0.9" font_awesome_flutter: dependency: "direct main" description: @@ -426,14 +370,14 @@ packages: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.0.1" image: dependency: "direct main" description: name: image url: "https://pub.dartlang.org" source: hosted - version: "3.1.3" + version: "3.2.0" image_picker: dependency: "direct main" description: @@ -461,7 +405,7 @@ packages: name: image_picker_ios url: "https://pub.dartlang.org" source: hosted - version: "0.8.5+4" + version: "0.8.5+5" image_picker_platform_interface: dependency: transitive description: @@ -560,20 +504,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.7" - nb_utils: - dependency: "direct main" - description: - name: nb_utils - url: "https://pub.dartlang.org" - source: hosted - version: "4.5.2" - nm: - dependency: transitive - description: - name: nm - url: "https://pub.dartlang.org" - source: hosted - version: "0.5.0" package_config: dependency: transitive description: @@ -736,7 +666,7 @@ packages: source: hosted version: "3.0.0" shared_preferences: - dependency: transitive + dependency: "direct main" description: name: shared_preferences url: "https://pub.dartlang.org" @@ -888,7 +818,7 @@ packages: source: hosted version: "1.3.1" url_launcher: - dependency: transitive + dependency: "direct main" description: name: url_launcher url: "https://pub.dartlang.org" @@ -907,7 +837,7 @@ packages: name: url_launcher_ios url: "https://pub.dartlang.org" source: hosted - version: "6.0.16" + version: "6.0.17" url_launcher_linux: dependency: transitive description: @@ -984,7 +914,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "5.4.1" + version: "6.1.0" yaml: dependency: transitive description: @@ -994,4 +924,4 @@ packages: version: "3.1.1" sdks: dart: ">=2.17.0 <3.0.0" - flutter: ">=2.10.0" + flutter: ">=3.0.0" diff --git a/zxscanner/pubspec.yaml b/zxscanner/pubspec.yaml index 19a7dcf..24dd7b6 100644 --- a/zxscanner/pubspec.yaml +++ b/zxscanner/pubspec.yaml @@ -22,13 +22,14 @@ dependencies: font_awesome_flutter: ^10.1.0 hive: ^2.2.1 hive_flutter: ^1.1.0 - image: ^3.1.3 + image: ^3.2.0 image_picker: ^0.8.5 intl: ^0.17.0 mobx: ^2.0.7 - nb_utils: ^4.5.2 path_provider: ^2.0.10 share_plus: ^4.0.4 + shared_preferences: ^2.0.15 + url_launcher: ^6.1.2 flutter_intl: main_locale: en_US