From 074ebb1871d2ed0306542567eeb9570f9fc99002 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Mon, 27 Feb 2023 17:09:58 +0100 Subject: [PATCH] finally instead of catch to secure if nothing is found an message is deplayed --- lib/widgets/scanner.dart | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/widgets/scanner.dart b/lib/widgets/scanner.dart index 76ec40a..b1aff7d 100644 --- a/lib/widgets/scanner.dart +++ b/lib/widgets/scanner.dart @@ -15,22 +15,26 @@ class MyScanner extends StatefulWidget { class MyScannerState extends State { bool scanning = false; - void handleError(String error) { + void handleError() { setState(() { scanning = false; showDialog( context: context, builder: (BuildContext context) { - return MissingConfigPopup( + return const MissingConfigPopup( title: 'Scanfehler', text: - 'Beim Scanen gab es folgende Meldung: $error. Bitte erneut versuchen', + 'Beim Scanen gab es wohl einen Fehler. Bitte erneut versuchen', ); }); }); } - void handleSucces(int group) { + void handleSucces(String? rawValue) { + String qrText = rawValue!; + Map json = stringToJSON(qrText); + Settings settings = Settings.fromJson(json); + saveSettings(settings); setState(() { scanning = false; showDialog( @@ -38,7 +42,7 @@ class MyScannerState extends State { builder: (BuildContext context) { return MissingConfigPopup( title: 'Konfiguration erfolgreich', - text: 'Du gehörst zu Gruppe $group', + text: 'Du gehörst zu Gruppe ${settings.group}', ); }); }); @@ -49,15 +53,11 @@ class MyScannerState extends State { final List barcodes = capture.barcodes; for (final barcode in barcodes) { if (barcode.rawValue != null) { - String qrText = barcode.rawValue!; - Map json = stringToJSON(qrText); - Settings settings = Settings.fromJson(json); - saveSettings(settings); - handleSucces(settings.group); + handleSucces(barcode.rawValue); } } - } catch (e) { - handleError(e.toString()); + } finally { + handleError(); } }