Browse Source

minor improvements

pull/3/head
Khoren Markosyan 3 years ago
parent
commit
f598aa876b
  1. 12
      example/pubspec.lock
  2. 2
      example/pubspec.yaml
  3. 2
      ios/Classes/src/native_zxing.cpp
  4. 4
      pubspec.yaml
  5. 12
      zxscanner/lib/configs/app_store.dart
  6. 29
      zxscanner/lib/main.dart
  7. 2
      zxscanner/lib/pages/barcodes_page.dart
  8. 22
      zxscanner/lib/pages/help_page.dart
  9. 2
      zxscanner/lib/pages/history_page.dart
  10. 100
      zxscanner/lib/utils/shared_pref.dart
  11. 94
      zxscanner/pubspec.lock
  12. 5
      zxscanner/pubspec.yaml

12
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"

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

2
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<uint32_t>(bitMatrix).data();
result.length = bitMatrix.width() * bitMatrix.height();

4
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

12
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<void> setThemeMode(ThemeMode value) async {
themeMode = value;
setValue(themeModePref, themeMode.toString());
setPrefValue(themeModePref, themeMode.toString());
}
@action
Future<void> setColorSchemeIndex(int value) async {
colorSchemeIndex = value;
await setValue(colorSchemeIndexPref, colorSchemeIndex);
await setPrefValue(colorSchemeIndexPref, colorSchemeIndex);
}
@action
Future<void> toggleSoundMode({bool? value}) async {
isSoundOn = value ?? !isSoundOn;
setValue(isSoundOnPref, isSoundOn);
setPrefValue(isSoundOnPref, isSoundOn);
}
@action
Future<void> toggleVibrationMode({bool? value}) async {
isVibrationOn = value ?? !isVibrationOn;
setValue(isVibrationOnPref, isVibrationOn);
setPrefValue(isVibrationOnPref, isVibrationOn);
}
@action
Future<void> setLanguage(String aLanguage) async {
selectedLanguage = aLanguage;
await setValue(languagePref, aLanguage);
await setPrefValue(languagePref, aLanguage);
}
}

29
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);

2
zxscanner/lib/pages/barcodes_page.dart

@ -51,6 +51,7 @@ class _BarcodesPageState extends State<BarcodesPage> {
itemBuilder: (context, index) {
final result = results[index];
return ContainerX(
child: Card(
child: ListTile(
leading: Image.memory(
result.data ?? Uint8List(0),
@ -81,6 +82,7 @@ class _BarcodesPageState extends State<BarcodesPage> {
],
),
),
),
);
},
);

22
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,11 +19,32 @@ class HelpPage extends StatelessWidget {
title: const Text('Help'),
),
body: ContainerX(
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),
),
),
],
),
),
);
}

2
zxscanner/lib/pages/history_page.dart

@ -42,6 +42,7 @@ class _HistoryPageState extends State<HistoryPage> {
itemBuilder: (context, index) {
final result = results[index];
return ContainerX(
child: Card(
child: ListTile(
title: Text(result.text ?? ''),
subtitle: Text(result.formatName),
@ -68,6 +69,7 @@ class _HistoryPageState extends State<HistoryPage> {
],
),
),
),
);
},
);

100
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<void> 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<String, dynamic> or StringList
Future<bool> 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<String, dynamic>) {
return await sharedPreferences.setString(key, jsonEncode(value));
} else if (value is List<String>) {
return await sharedPreferences.setStringList(key, value);
} else {
throw ArgumentError(
'Invalid value ${value.runtimeType} - Must be a String, int, bool, double, Map<String, dynamic> or StringList');
}
}
/// Returns List of Keys that matches with given Key
List<String> getMatchingSharedPrefKeys(String key) {
List<String> keys = [];
sharedPreferences.getKeys().forEach((element) {
if (element.contains(key)) {
keys.add(element);
}
});
return keys;
}
/// Returns a StringList if exists in SharedPref
List<String>? 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<String, dynamic> getPrefJSON(String key,
{Map<String, dynamic>? defaultValue}) {
if (sharedPreferences.containsKey(key)) {
return jsonDecode(sharedPreferences.getString(key) ?? '');
} else {
return defaultValue ?? {};
}
}
/// remove key from SharedPref
Future<bool> removePrefKey(String key) async =>
await sharedPreferences.remove(key);
/// clear SharedPref
Future<bool> clearSharedPref() async => await sharedPreferences.clear();

94
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"

5
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

Loading…
Cancel
Save