From abd531be1f55cb8decbd3bd9bf45a4cb218b8a62 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 21 May 2024 15:14:04 +0200 Subject: [PATCH] bugfix: show error message when scan fails due to the extra Navigator.pop(), we would immediately close the error dialog after opening it, rendering it practically invisible. to handle back button in non-error cases, we now simply accept the null value --- lib/widgets/nutrition/widgets.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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), ); } }