finally instead of catch to secure if nothing is found an message is deplayed
parent
3909bfd66c
commit
074ebb1871
|
@ -15,22 +15,26 @@ class MyScanner extends StatefulWidget {
|
||||||
class MyScannerState extends State<MyScanner> {
|
class MyScannerState extends State<MyScanner> {
|
||||||
bool scanning = false;
|
bool scanning = false;
|
||||||
|
|
||||||
void handleError(String error) {
|
void handleError() {
|
||||||
setState(() {
|
setState(() {
|
||||||
scanning = false;
|
scanning = false;
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return MissingConfigPopup(
|
return const MissingConfigPopup(
|
||||||
title: 'Scanfehler',
|
title: 'Scanfehler',
|
||||||
text:
|
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(() {
|
setState(() {
|
||||||
scanning = false;
|
scanning = false;
|
||||||
showDialog(
|
showDialog(
|
||||||
|
@ -38,7 +42,7 @@ class MyScannerState extends State<MyScanner> {
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return MissingConfigPopup(
|
return MissingConfigPopup(
|
||||||
title: 'Konfiguration erfolgreich',
|
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;
|
final List<Barcode> barcodes = capture.barcodes;
|
||||||
for (final barcode in barcodes) {
|
for (final barcode in barcodes) {
|
||||||
if (barcode.rawValue != null) {
|
if (barcode.rawValue != null) {
|
||||||
String qrText = barcode.rawValue!;
|
handleSucces(barcode.rawValue);
|
||||||
Map<String, dynamic> json = stringToJSON(qrText);
|
|
||||||
Settings settings = Settings.fromJson(json);
|
|
||||||
saveSettings(settings);
|
|
||||||
handleSucces(settings.group);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} finally {
|
||||||
handleError(e.toString());
|
handleError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue