@@ -21,6 +21,7 @@ import 'package:flutter/services.dart';
21
21
import 'package:flutter_typeahead/flutter_typeahead.dart' ;
22
22
import 'package:flutter_zxing/flutter_zxing.dart' ;
23
23
import 'package:font_awesome_flutter/font_awesome_flutter.dart' ;
24
+ import 'package:logging/logging.dart' ;
24
25
import 'package:provider/provider.dart' ;
25
26
import 'package:wger/helpers/consts.dart' ;
26
27
import 'package:wger/helpers/misc.dart' ;
@@ -54,18 +55,20 @@ class ScanReader extends StatelessWidget {
54
55
}
55
56
56
57
class IngredientTypeahead extends StatefulWidget {
58
+ final _logger = Logger ('IngredientTypeahead' );
59
+
57
60
final TextEditingController _ingredientController;
58
61
final TextEditingController _ingredientIdController;
59
62
60
63
final String barcode;
61
- final bool ? test;
64
+ final bool test;
62
65
final bool showScanner;
63
66
64
67
final Function (int id, String name, num ? amount) selectIngredient;
65
68
final Function () unSelectIngredient;
66
69
final Function (String query) updateSearchQuery;
67
70
68
- const IngredientTypeahead (
71
+ IngredientTypeahead (
69
72
this ._ingredientIdController,
70
73
this ._ingredientController, {
71
74
this .showScanner = true ,
@@ -90,19 +93,21 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
90
93
barcode = widget.barcode; // for unit tests
91
94
}
92
95
93
- Future <String > readerscan (BuildContext context) async {
96
+ Future <String > openBarcodeScan (BuildContext context) async {
94
97
try {
95
98
final code = await Navigator .of (context)
96
99
.push <String ?>(MaterialPageRoute (builder: (context) => const ScanReader ()));
100
+
97
101
if (code == null ) {
98
102
return '' ;
99
103
}
100
104
101
- if (code. compareTo ( '-1' ) == 0 ) {
105
+ if (code == '-1' ) {
102
106
return '' ;
103
107
}
104
108
return code;
105
- } on PlatformException {
109
+ } on PlatformException catch (e) {
110
+ widget._logger.warning ('PlatformException during barcode scan: $e ' );
106
111
return '' ;
107
112
}
108
113
}
@@ -202,8 +207,8 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
202
207
key: const Key ('scan-button' ),
203
208
icon: const FaIcon (FontAwesomeIcons .barcode),
204
209
onPressed: () async {
205
- if (! widget.test! ) {
206
- barcode = await readerscan (context);
210
+ if (! widget.test) {
211
+ barcode = await openBarcodeScan (context);
207
212
}
208
213
209
214
if (! mounted) {
0 commit comments