Skip to content

Commit 1c969eb

Browse files
committed
Add logging to IngredientTypeahead
1 parent 823b501 commit 1c969eb

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/widgets/nutrition/widgets.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import 'package:flutter/services.dart';
2121
import 'package:flutter_typeahead/flutter_typeahead.dart';
2222
import 'package:flutter_zxing/flutter_zxing.dart';
2323
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
24+
import 'package:logging/logging.dart';
2425
import 'package:provider/provider.dart';
2526
import 'package:wger/helpers/consts.dart';
2627
import 'package:wger/helpers/misc.dart';
@@ -54,18 +55,20 @@ class ScanReader extends StatelessWidget {
5455
}
5556

5657
class IngredientTypeahead extends StatefulWidget {
58+
final _logger = Logger('IngredientTypeahead');
59+
5760
final TextEditingController _ingredientController;
5861
final TextEditingController _ingredientIdController;
5962

6063
final String barcode;
61-
final bool? test;
64+
final bool test;
6265
final bool showScanner;
6366

6467
final Function(int id, String name, num? amount) selectIngredient;
6568
final Function() unSelectIngredient;
6669
final Function(String query) updateSearchQuery;
6770

68-
const IngredientTypeahead(
71+
IngredientTypeahead(
6972
this._ingredientIdController,
7073
this._ingredientController, {
7174
this.showScanner = true,
@@ -90,19 +93,21 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
9093
barcode = widget.barcode; // for unit tests
9194
}
9295

93-
Future<String> readerscan(BuildContext context) async {
96+
Future<String> openBarcodeScan(BuildContext context) async {
9497
try {
9598
final code = await Navigator.of(context)
9699
.push<String?>(MaterialPageRoute(builder: (context) => const ScanReader()));
100+
97101
if (code == null) {
98102
return '';
99103
}
100104

101-
if (code.compareTo('-1') == 0) {
105+
if (code == '-1') {
102106
return '';
103107
}
104108
return code;
105-
} on PlatformException {
109+
} on PlatformException catch (e) {
110+
widget._logger.warning('PlatformException during barcode scan: $e');
106111
return '';
107112
}
108113
}
@@ -202,8 +207,8 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
202207
key: const Key('scan-button'),
203208
icon: const FaIcon(FontAwesomeIcons.barcode),
204209
onPressed: () async {
205-
if (!widget.test!) {
206-
barcode = await readerscan(context);
210+
if (!widget.test) {
211+
barcode = await openBarcodeScan(context);
207212
}
208213

209214
if (!mounted) {

0 commit comments

Comments
 (0)