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. 58
      zxscanner/lib/pages/barcodes_page.dart
  8. 28
      zxscanner/lib/pages/help_page.dart
  9. 50
      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 name: camera
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.9.5+1" version: "0.9.7"
camera_platform_interface: camera_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -77,7 +77,7 @@ packages:
name: cross_file name: cross_file
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.3.3" version: "0.3.3+1"
crypto: crypto:
dependency: transitive dependency: transitive
description: description:
@ -162,14 +162,14 @@ packages:
name: http_parser name: http_parser
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.0.0" version: "4.0.1"
image: image:
dependency: "direct main" dependency: "direct main"
description: description:
name: image name: image
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.1.3" version: "3.2.0"
image_picker: image_picker:
dependency: "direct main" dependency: "direct main"
description: description:
@ -197,7 +197,7 @@ packages:
name: image_picker_ios name: image_picker_ios
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.8.5+4" version: "0.8.5+5"
image_picker_platform_interface: image_picker_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -342,7 +342,7 @@ packages:
name: xml name: xml
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.4.1" version: "6.1.0"
sdks: sdks:
dart: ">=2.17.0 <3.0.0" dart: ">=2.17.0 <3.0.0"
flutter: ">=2.8.0" flutter: ">=2.8.0"

2
example/pubspec.yaml

@ -12,7 +12,7 @@ dependencies:
flutter_zxing: flutter_zxing:
path: ../ path: ../
font_awesome_flutter: ^10.1.0 font_awesome_flutter: ^10.1.0
image: ^3.1.3 image: ^3.2.0
image_picker: ^0.8.5 image_picker: ^0.8.5
dev_dependencies: 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}; struct EncodeResult result = {0, contents, Format(format), nullptr, 0, nullptr};
try 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); auto bitMatrix = writer.encode(TextUtfEncoding::FromUtf8(std::string(contents)), width, height);
result.data = ToMatrix<uint32_t>(bitMatrix).data(); result.data = ToMatrix<uint32_t>(bitMatrix).data();
result.length = bitMatrix.width() * bitMatrix.height(); result.length = bitMatrix.width() * bitMatrix.height();

4
pubspec.yaml

@ -8,12 +8,12 @@ environment:
flutter: ">=2.5.0" flutter: ">=2.5.0"
dependencies: dependencies:
camera: ^0.9.5 camera: ^0.9.7
ffi: ^1.2.1 ffi: ^1.2.1
flutter: flutter:
sdk: flutter sdk: flutter
flutter_beep: ^1.0.0 flutter_beep: ^1.0.0
image: ^3.1.3 image: ^3.2.0
dev_dependencies: dev_dependencies:
ffigen: ^5.0.0 # dart run ffigen 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:flutter/material.dart';
import 'package:mobx/mobx.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'; part 'app_store.g.dart';
@ -33,30 +33,30 @@ abstract class AppStoreBase with Store {
@action @action
Future<void> setThemeMode(ThemeMode value) async { Future<void> setThemeMode(ThemeMode value) async {
themeMode = value; themeMode = value;
setValue(themeModePref, themeMode.toString()); setPrefValue(themeModePref, themeMode.toString());
} }
@action @action
Future<void> setColorSchemeIndex(int value) async { Future<void> setColorSchemeIndex(int value) async {
colorSchemeIndex = value; colorSchemeIndex = value;
await setValue(colorSchemeIndexPref, colorSchemeIndex); await setPrefValue(colorSchemeIndexPref, colorSchemeIndex);
} }
@action @action
Future<void> toggleSoundMode({bool? value}) async { Future<void> toggleSoundMode({bool? value}) async {
isSoundOn = value ?? !isSoundOn; isSoundOn = value ?? !isSoundOn;
setValue(isSoundOnPref, isSoundOn); setPrefValue(isSoundOnPref, isSoundOn);
} }
@action @action
Future<void> toggleVibrationMode({bool? value}) async { Future<void> toggleVibrationMode({bool? value}) async {
isVibrationOn = value ?? !isVibrationOn; isVibrationOn = value ?? !isVibrationOn;
setValue(isVibrationOnPref, isVibrationOn); setPrefValue(isVibrationOnPref, isVibrationOn);
} }
@action @action
Future<void> setLanguage(String aLanguage) async { Future<void> setLanguage(String aLanguage) async {
selectedLanguage = aLanguage; 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/configs/constants.dart';
import 'package:zxscanner/utils/db_service.dart'; import 'package:zxscanner/utils/db_service.dart';
import 'package:zxscanner/utils/extensions.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_store.dart';
import 'configs/app_theme.dart'; import 'configs/app_theme.dart';
@ -14,36 +14,11 @@ import 'utils/scroll_behavior.dart';
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await _initializeAppStore(); await initializePrefs();
await DbService.instance.initializeApp(); await DbService.instance.initializeApp();
runApp(const MyApp()); 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 { class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key); const MyApp({Key? key}) : super(key: key);

58
zxscanner/lib/pages/barcodes_page.dart

@ -51,34 +51,36 @@ class _BarcodesPageState extends State<BarcodesPage> {
itemBuilder: (context, index) { itemBuilder: (context, index) {
final result = results[index]; final result = results[index];
return ContainerX( return ContainerX(
child: ListTile( child: Card(
leading: Image.memory( child: ListTile(
result.data ?? Uint8List(0), leading: Image.memory(
width: 60, result.data ?? Uint8List(0),
), width: 60,
title: Text(result.text ?? ''), ),
subtitle: Text(result.formatName), title: Text(result.text ?? ''),
trailing: ButtonBar( subtitle: Text(result.formatName),
mainAxisSize: MainAxisSize.min, trailing: ButtonBar(
children: [ mainAxisSize: MainAxisSize.min,
// Copy button children: [
IconButton( // Copy button
icon: const Icon(FontAwesomeIcons.copy), IconButton(
onPressed: () { icon: const Icon(FontAwesomeIcons.copy),
Clipboard.setData( onPressed: () {
ClipboardData(text: result.text)); Clipboard.setData(
}, ClipboardData(text: result.text));
), },
// Remove button ),
IconButton( // Remove button
icon: const Icon(FontAwesomeIcons.trash, IconButton(
color: Colors.red), icon: const Icon(FontAwesomeIcons.trash,
onPressed: () { color: Colors.red),
DbService.instance.deleteEncode(result); onPressed: () {
setState(() {}); DbService.instance.deleteEncode(result);
}, setState(() {});
), },
], ),
],
),
), ),
), ),
); );

28
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:flutter_zxing/flutter_zxing.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:image/image.dart' as imglib; import 'package:image/image.dart' as imglib;
import 'package:url_launcher/url_launcher_string.dart';
import 'package:zxscanner/configs/constants.dart'; import 'package:zxscanner/configs/constants.dart';
import 'package:zxscanner/widgets/common_widgets.dart'; import 'package:zxscanner/widgets/common_widgets.dart';
@ -18,9 +19,30 @@ class HelpPage extends StatelessWidget {
title: const Text('Help'), title: const Text('Help'),
), ),
body: ContainerX( body: ContainerX(
child: ListView( child: Column(
padding: const EdgeInsets.only(bottom: spaceLarge2), children: [
children: createSlides(context), 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),
),
),
],
), ),
), ),
); );

50
zxscanner/lib/pages/history_page.dart

@ -42,30 +42,32 @@ class _HistoryPageState extends State<HistoryPage> {
itemBuilder: (context, index) { itemBuilder: (context, index) {
final result = results[index]; final result = results[index];
return ContainerX( return ContainerX(
child: ListTile( child: Card(
title: Text(result.text ?? ''), child: ListTile(
subtitle: Text(result.formatName), title: Text(result.text ?? ''),
trailing: ButtonBar( subtitle: Text(result.formatName),
mainAxisSize: MainAxisSize.min, trailing: ButtonBar(
children: [ mainAxisSize: MainAxisSize.min,
// Copy button children: [
IconButton( // Copy button
icon: const Icon(FontAwesomeIcons.copy), IconButton(
onPressed: () { icon: const Icon(FontAwesomeIcons.copy),
Clipboard.setData( onPressed: () {
ClipboardData(text: result.text)); Clipboard.setData(
}, ClipboardData(text: result.text));
), },
// Remove button ),
IconButton( // Remove button
icon: const Icon(FontAwesomeIcons.trash, IconButton(
color: Colors.red), icon: const Icon(FontAwesomeIcons.trash,
onPressed: () { color: Colors.red),
DbService.instance.deleteCode(result); onPressed: () {
setState(() {}); DbService.instance.deleteCode(result);
}, setState(() {});
), },
], ),
],
),
), ),
), ),
); );

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 name: built_value
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "8.3.0" version: "8.3.2"
camera: camera:
dependency: transitive dependency: transitive
description: description:
name: camera name: camera
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.9.5+1" version: "0.9.7"
camera_platform_interface: camera_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -162,48 +162,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.16.0" 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: convert:
dependency: transitive dependency: transitive
description: description:
@ -224,7 +182,7 @@ packages:
name: cross_file name: cross_file
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.3.3" version: "0.3.3+1"
crypto: crypto:
dependency: transitive dependency: transitive
description: description:
@ -246,13 +204,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.2.3" version: "2.2.3"
dbus:
dependency: transitive
description:
name: dbus
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.3"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
@ -318,7 +269,7 @@ packages:
name: flutter_markdown name: flutter_markdown
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.6.10" version: "0.6.10+1"
flutter_mobx: flutter_mobx:
dependency: "direct main" dependency: "direct main"
description: description:
@ -350,13 +301,6 @@ packages:
relative: true relative: true
source: path source: path
version: "0.1.2" version: "0.1.2"
fluttertoast:
dependency: transitive
description:
name: fluttertoast
url: "https://pub.dartlang.org"
source: hosted
version: "8.0.9"
font_awesome_flutter: font_awesome_flutter:
dependency: "direct main" dependency: "direct main"
description: description:
@ -426,14 +370,14 @@ packages:
name: http_parser name: http_parser
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.0.0" version: "4.0.1"
image: image:
dependency: "direct main" dependency: "direct main"
description: description:
name: image name: image
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.1.3" version: "3.2.0"
image_picker: image_picker:
dependency: "direct main" dependency: "direct main"
description: description:
@ -461,7 +405,7 @@ packages:
name: image_picker_ios name: image_picker_ios
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.8.5+4" version: "0.8.5+5"
image_picker_platform_interface: image_picker_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -560,20 +504,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.7" 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: package_config:
dependency: transitive dependency: transitive
description: description:
@ -736,7 +666,7 @@ packages:
source: hosted source: hosted
version: "3.0.0" version: "3.0.0"
shared_preferences: shared_preferences:
dependency: transitive dependency: "direct main"
description: description:
name: shared_preferences name: shared_preferences
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
@ -888,7 +818,7 @@ packages:
source: hosted source: hosted
version: "1.3.1" version: "1.3.1"
url_launcher: url_launcher:
dependency: transitive dependency: "direct main"
description: description:
name: url_launcher name: url_launcher
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
@ -907,7 +837,7 @@ packages:
name: url_launcher_ios name: url_launcher_ios
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "6.0.16" version: "6.0.17"
url_launcher_linux: url_launcher_linux:
dependency: transitive dependency: transitive
description: description:
@ -984,7 +914,7 @@ packages:
name: xml name: xml
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.4.1" version: "6.1.0"
yaml: yaml:
dependency: transitive dependency: transitive
description: description:
@ -994,4 +924,4 @@ packages:
version: "3.1.1" version: "3.1.1"
sdks: sdks:
dart: ">=2.17.0 <3.0.0" 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 font_awesome_flutter: ^10.1.0
hive: ^2.2.1 hive: ^2.2.1
hive_flutter: ^1.1.0 hive_flutter: ^1.1.0
image: ^3.1.3 image: ^3.2.0
image_picker: ^0.8.5 image_picker: ^0.8.5
intl: ^0.17.0 intl: ^0.17.0
mobx: ^2.0.7 mobx: ^2.0.7
nb_utils: ^4.5.2
path_provider: ^2.0.10 path_provider: ^2.0.10
share_plus: ^4.0.4 share_plus: ^4.0.4
shared_preferences: ^2.0.15
url_launcher: ^6.1.2
flutter_intl: flutter_intl:
main_locale: en_US main_locale: en_US

Loading…
Cancel
Save