From d896fab4ad73f52d1c63bb9283d9e260ab833def Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 21 May 2024 15:50:26 +0200 Subject: [PATCH] cleanup --- lib/widgets/nutrition/widgets.dart | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/widgets/nutrition/widgets.dart b/lib/widgets/nutrition/widgets.dart index f5a5a82b..ddd490c0 100644 --- a/lib/widgets/nutrition/widgets.dart +++ b/lib/widgets/nutrition/widgets.dart @@ -39,6 +39,13 @@ class ScanReader extends StatelessWidget { Widget build(BuildContext context) => Scaffold( body: ReaderWidget( onScan: (result) { + // notes: + // 1. even if result.isValid, result.error is always non-null (and set to "") + // 2. i've never encountered scan errors to see when they occur, and + // i wouldn't know what to do about them anyway, so we simply return + // result.text in such case (which presumably will be null, or "") + // 3. when user cancels (swipe left / back button) this code is no longer + // run and the caller receives null Navigator.pop(context, result.text); }, ), @@ -72,22 +79,20 @@ class _IngredientTypeaheadState extends State { var _searchEnglish = true; Future readerscan(BuildContext context) async { - String? scannedcode; try { - scannedcode = - await Navigator.of(context).push(MaterialPageRoute(builder: (context) => ScanReader())); - if (scannedcode == null) { + final code = await Navigator.of(context) + .push(MaterialPageRoute(builder: (context) => ScanReader())); + if (code == null) { return ''; } - if (scannedcode.compareTo('-1') == 0) { + if (code.compareTo('-1') == 0) { return ''; } + return code; } on PlatformException { return ''; } - - return scannedcode; } @override