diff --git a/lib/widgets/nutrition/widgets.dart b/lib/widgets/nutrition/widgets.dart index 9843aa53..68be4f9a 100644 --- a/lib/widgets/nutrition/widgets.dart +++ b/lib/widgets/nutrition/widgets.dart @@ -75,10 +75,13 @@ class _IngredientTypeaheadState extends State { var _searchEnglish = true; Future readerscan(BuildContext context) async { - String scannedcode; + String? scannedcode; try { scannedcode = await Navigator.of(context).push(MaterialPageRoute(builder: (context) => ScanReader())); + if (scannedcode == null) { + return ''; + } if (scannedcode.compareTo('-1') == 0) { return ''; @@ -164,6 +167,7 @@ class _IngredientTypeaheadState extends State { Widget scanButton() { return IconButton( key: const Key('scan-button'), + icon: const FaIcon(FontAwesomeIcons.barcode), onPressed: () async { try { if (!widget.test!) { @@ -228,15 +232,11 @@ class _IngredientTypeaheadState extends State { } } } catch (e) { - if (context.mounted) { + if (mounted) { showErrorDialog(e, context); - // Need to pop back since reader scan is a widget - // otherwise returns null when back button is pressed - return Navigator.pop(context); } } }, - icon: const FaIcon(FontAwesomeIcons.barcode), ); } }