Skip to content

Commit 7857e17

Browse files
authored
Merge pull request #411 from artchiee/google_play_dependency
Flutter barcode scanner replaced with flutter_zxing package
2 parents 1bbf2c4 + 72e9f4b commit 7857e17

File tree

10 files changed

+206
-27
lines changed

10 files changed

+206
-27
lines changed

.vscode/settings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"dart.lineLength": 100,
3-
"diffEditor.ignoreTrimWhitespace": true,
4-
}
2+
"dart.lineLength": 100,
3+
"diffEditor.ignoreTrimWhitespace": true,
4+
}

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- Aman Negi - <https://github.com/AmanNegi>
2121
- Sandi Milohanic - <https://github.com/sandimilohanic>
2222
- Miroslav Mazel - <https://gitlab.com/12people>
23+
- artchiee - <https://github.com/artchiee>
2324
- Tejas Bir Singh - <https://github.com/tejasbirsingh>
2425

2526
## Translators

flatpak/scripts/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ packages:
8282
source: hosted
8383
version: "1.3.1"
8484
sdks:
85-
dart: ">=2.18.5 <3.0.0"
85+
dart: ">=2.18.5 <4.0.0"

lib/main.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ import 'package:wger/theme/theme.dart';
5050
import 'package:wger/widgets/core/about.dart';
5151

5252
import 'providers/auth.dart';
53+
import 'package:flutter/foundation.dart';
54+
import 'package:flutter_zxing/flutter_zxing.dart';
55+
5356

5457
void main() {
58+
zx.setLogEnabled(kDebugMode);
5559
// Needs to be called before runApp
5660
WidgetsFlutterBinding.ensureInitialized();
5761

lib/widgets/nutrition/widgets.dart

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,47 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19+
import 'dart:developer';
20+
import 'dart:io';
21+
1922
import 'package:flutter/material.dart';
2023
import 'package:flutter/services.dart';
21-
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
24+
//import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
2225
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2326
import 'package:flutter_typeahead/flutter_typeahead.dart';
27+
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
2428
import 'package:provider/provider.dart';
2529
import 'package:wger/helpers/consts.dart';
2630
import 'package:wger/helpers/platform.dart';
2731
import 'package:wger/helpers/ui.dart';
2832
import 'package:wger/providers/nutrition.dart';
2933
import 'package:wger/widgets/core/core.dart';
3034

35+
import 'package:flutter_zxing/flutter_zxing.dart';
36+
37+
38+
class ScanReader extends StatelessWidget {
39+
String? scannedr;
40+
41+
@override
42+
Widget build(BuildContext context) => Scaffold(
43+
body: ReaderWidget(
44+
onScan: (result) {
45+
scannedr = result.text;
46+
Navigator.pop(context, scannedr);
47+
},
48+
),
49+
);
50+
51+
}
52+
3153
class IngredientTypeahead extends StatefulWidget {
3254
final TextEditingController _ingredientController;
3355
final TextEditingController _ingredientIdController;
3456

3557
String? barcode = '';
58+
//Code? result;
59+
3660
late final bool? test;
3761
final bool showScanner;
3862

@@ -48,28 +72,24 @@ class IngredientTypeahead extends StatefulWidget {
4872
_IngredientTypeaheadState createState() => _IngredientTypeaheadState();
4973
}
5074

51-
Future<String> scanBarcode(BuildContext context) async {
52-
String barcode;
53-
try {
54-
barcode = await FlutterBarcodeScanner.scanBarcode(
55-
'#ff6666',
56-
AppLocalizations.of(context).close,
57-
true,
58-
ScanMode.BARCODE,
59-
);
75+
class _IngredientTypeaheadState extends State<IngredientTypeahead> {
76+
var _searchEnglish = true;
6077

61-
if (barcode.compareTo('-1') == 0) {
78+
Future<String> readerscan(BuildContext context) async {
79+
String scannedcode;
80+
try {
81+
scannedcode =
82+
await Navigator.of(context).push(MaterialPageRoute(builder: (context) => ScanReader()));
83+
84+
if (scannedcode.compareTo('-1') == 0) {
85+
return '';
86+
}
87+
} on PlatformException {
6288
return '';
6389
}
64-
} on PlatformException {
65-
return '';
66-
}
6790

68-
return barcode;
69-
}
70-
71-
class _IngredientTypeaheadState extends State<IngredientTypeahead> {
72-
var _searchEnglish = true;
91+
return scannedcode;
92+
}
7393

7494
@override
7595
Widget build(BuildContext context) {
@@ -136,7 +156,7 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
136156
onPressed: () async {
137157
try {
138158
if (!widget.test!) {
139-
widget.barcode = await scanBarcode(context);
159+
widget.barcode = await readerscan(context);
140160
}
141161

142162
if (widget.barcode!.isNotEmpty) {
@@ -195,6 +215,9 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
195215
}
196216
} catch (e) {
197217
showErrorDialog(e, context);
218+
// Need to pop back since reader scan is a widget
219+
// otherwise returns null when back button is pressed
220+
return Navigator.pop(context);
198221
}
199222
},
200223
icon: Image.asset('assets/images/barcode_scanner_icon.png'),

linux/flutter/generated_plugin_registrant.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66

77
#include "generated_plugin_registrant.h"
88

9+
#include <file_selector_linux/file_selector_plugin.h>
910
#include <url_launcher_linux/url_launcher_plugin.h>
1011

1112
void fl_register_plugins(FlPluginRegistry* registry) {
13+
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
14+
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
15+
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
1216
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
1317
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
1418
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);

linux/flutter/generated_plugins.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
#
44

55
list(APPEND FLUTTER_PLUGIN_LIST
6+
file_selector_linux
67
url_launcher_linux
78
)
89

910
list(APPEND FLUTTER_FFI_PLUGIN_LIST
11+
flutter_zxing
1012
)
1113

1214
set(PLUGIN_BUNDLED_LIBRARIES)

macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import FlutterMacOS
66
import Foundation
77

8+
import file_selector_macos
89
import package_info_plus
910
import rive_common
1011
import shared_preferences_foundation
1112
import url_launcher_macos
1213

1314
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
15+
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
1416
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
1517
RivePlugin.register(with: registry.registrar(forPlugin: "RivePlugin"))
1618
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))

0 commit comments

Comments
 (0)