16
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
*/
18
18
19
+ import 'dart:developer' ;
20
+ import 'dart:io' ;
21
+
19
22
import 'package:flutter/material.dart' ;
20
23
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';
22
25
import 'package:flutter_gen/gen_l10n/app_localizations.dart' ;
23
26
import 'package:flutter_typeahead/flutter_typeahead.dart' ;
27
+ import 'package:font_awesome_flutter/font_awesome_flutter.dart' ;
24
28
import 'package:provider/provider.dart' ;
25
29
import 'package:wger/helpers/consts.dart' ;
26
30
import 'package:wger/helpers/platform.dart' ;
27
31
import 'package:wger/helpers/ui.dart' ;
28
32
import 'package:wger/providers/nutrition.dart' ;
29
33
import 'package:wger/widgets/core/core.dart' ;
30
34
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
+
31
53
class IngredientTypeahead extends StatefulWidget {
32
54
final TextEditingController _ingredientController;
33
55
final TextEditingController _ingredientIdController;
34
56
35
57
String ? barcode = '' ;
58
+ //Code? result;
59
+
36
60
late final bool ? test;
37
61
final bool showScanner;
38
62
@@ -48,28 +72,24 @@ class IngredientTypeahead extends StatefulWidget {
48
72
_IngredientTypeaheadState createState () => _IngredientTypeaheadState ();
49
73
}
50
74
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 ;
60
77
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 {
62
88
return '' ;
63
89
}
64
- } on PlatformException {
65
- return '' ;
66
- }
67
90
68
- return barcode;
69
- }
70
-
71
- class _IngredientTypeaheadState extends State <IngredientTypeahead > {
72
- var _searchEnglish = true ;
91
+ return scannedcode;
92
+ }
73
93
74
94
@override
75
95
Widget build (BuildContext context) {
@@ -136,7 +156,7 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
136
156
onPressed: () async {
137
157
try {
138
158
if (! widget.test! ) {
139
- widget.barcode = await scanBarcode (context);
159
+ widget.barcode = await readerscan (context);
140
160
}
141
161
142
162
if (widget.barcode! .isNotEmpty) {
@@ -195,6 +215,9 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
195
215
}
196
216
} catch (e) {
197
217
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);
198
221
}
199
222
},
200
223
icon: Image .asset ('assets/images/barcode_scanner_icon.png' ),
0 commit comments