mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
bugfix: show error message when scan fails
due to the extra Navigator.pop(), we would immediately close the error dialog after opening it, rendering it practically invisible. to handle back button in non-error cases, we now simply accept the null value
This commit is contained in:
@@ -75,10 +75,13 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
|
||||
var _searchEnglish = true;
|
||||
|
||||
Future<String> readerscan(BuildContext context) async {
|
||||
String scannedcode;
|
||||
String? scannedcode;
|
||||
try {
|
||||
scannedcode =
|
||||
await Navigator.of(context).push(MaterialPageRoute(builder: (context) => ScanReader()));
|
||||
if (scannedcode == null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (scannedcode.compareTo('-1') == 0) {
|
||||
return '';
|
||||
@@ -164,6 +167,7 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
|
||||
Widget scanButton() {
|
||||
return IconButton(
|
||||
key: const Key('scan-button'),
|
||||
icon: const FaIcon(FontAwesomeIcons.barcode),
|
||||
onPressed: () async {
|
||||
try {
|
||||
if (!widget.test!) {
|
||||
@@ -228,15 +232,11 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
if (mounted) {
|
||||
showErrorDialog(e, context);
|
||||
// Need to pop back since reader scan is a widget
|
||||
// otherwise returns null when back button is pressed
|
||||
return Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
},
|
||||
icon: const FaIcon(FontAwesomeIcons.barcode),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user