finally instead of catch to secure if nothing is found an message is deplayed

main
Kai Mannweiler 2023-02-27 17:09:58 +01:00
parent 3909bfd66c
commit 074ebb1871
1 changed files with 12 additions and 12 deletions

View File

@ -15,22 +15,26 @@ class MyScanner extends StatefulWidget {
class MyScannerState extends State<MyScanner> {
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<String, dynamic> json = stringToJSON(qrText);
Settings settings = Settings.fromJson(json);
saveSettings(settings);
setState(() {
scanning = false;
showDialog(
@ -38,7 +42,7 @@ class MyScannerState extends State<MyScanner> {
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<MyScanner> {
final List<Barcode> barcodes = capture.barcodes;
for (final barcode in barcodes) {
if (barcode.rawValue != null) {
String qrText = barcode.rawValue!;
Map<String, dynamic> json = stringToJSON(qrText);
Settings settings = Settings.fromJson(json);
saveSettings(settings);
handleSucces(settings.group);
handleSucces(barcode.rawValue);
}
}
} catch (e) {
handleError(e.toString());
} finally {
handleError();
}
}