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:
Dieter Plaetinck
2024-05-21 15:14:04 +02:00
parent 721dd5e298
commit abd531be1f

View File

@@ -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),
);
}
}