From c56222660d411c08ecc3e65e81cb8d8db6acc9a6 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Fri, 3 Mar 2023 18:34:24 +0100 Subject: [PATCH] Added try catch with errorhandling --- lib/widgets/scanner.dart | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/widgets/scanner.dart b/lib/widgets/scanner.dart index 46f8c8a..b635d67 100644 --- a/lib/widgets/scanner.dart +++ b/lib/widgets/scanner.dart @@ -37,12 +37,28 @@ class MyScannerState extends State { }); } + void handleError() { + setState(() { + scanning = false; + AwesomeDialog( + context: context, + dialogType: DialogType.error, + title: 'Fehler', + desc: 'Der QR-Code war fehlerhaft!', + ).show(); + }); + } + void onDetect(capture) { - final List barcodes = capture.barcodes; - for (final barcode in barcodes) { - if (barcode.rawValue != null) { - return handleSucces(barcode.rawValue); + try { + final List barcodes = capture.barcodes; + for (final barcode in barcodes) { + if (barcode.rawValue != null) { + return handleSucces(barcode.rawValue); + } } + } catch (e) { + handleError(); } }