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(); } }