2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00

Improve error handling for barcode

- Only resume barcode camera when the error dialog is dismissed
This commit is contained in:
Oliver Walters 2020-05-26 23:40:41 +10:00
parent 6102b39e9d
commit 02982cea5e

View File

@ -55,17 +55,14 @@ class _QRViewState extends State<InvenTreeQRView> {
print(response.body); print(response.body);
if (response.statusCode != 200) { if (response.statusCode != 200) {
showDialog(
context: context, showErrorDialog(
child: new SimpleDialog( context,
title: Text("Server Error"), "Server Error: ${response.statusCode}",
children: <Widget>[ "${response.body.toString().split('\n').first}",
ListTile( onDismissed: () {
title: Text("Error ${response.statusCode}"), _controller.resumeCamera();
subtitle: Text("${response.body.toString().split("\n").first}"), }
)
],
),
); );
return; return;
@ -76,37 +73,31 @@ class _QRViewState extends State<InvenTreeQRView> {
// "Error" contained in response // "Error" contained in response
if (body.containsKey('error')) { if (body.containsKey('error')) {
showDialog(
context: context,
child: new SimpleDialog(
title: Text("Barcode Error"),
children: <Widget>[
ListTile(
title: Text("${body['error']}"),
subtitle: Text(
"Plugin: ${body['plugin'] ?? '<no plugin information>'}"),
)
],
)
);
showErrorDialog(
context,
body['error'] ?? '',
body['plugin'] ?? 'No barcode plugin information',
error: "Barcode Error",
onDismissed: () {
_controller.resumeCamera();
}
);
return; return;
} else if (body.containsKey('success')) { } else if (body.containsKey('success')) {
// Decode the barcode! // Decode the barcode!
// Ideally, the server has returned unto us something sensible... // Ideally, the server has returned unto us something sensible...
_handleBarcode(context, body); _handleBarcode(context, body);
} else { } else {
showDialog(
context: context, showErrorDialog(
child: new SimpleDialog( context,
title: Text("Unknown response"), "Response Data",
children: <Widget>[ body.toString(),
ListTile( error: "Unknown Response",
title: Text("Response data"), onDismissed: () {
subtitle: Text("${body.toString()}"), _controller.resumeCamera();
) }
],
)
); );
} }
@ -114,22 +105,24 @@ class _QRViewState extends State<InvenTreeQRView> {
Duration(seconds: 5) Duration(seconds: 5)
).catchError((error) { ).catchError((error) {
hideProgressDialog(context); hideProgressDialog(context);
showErrorDialog(context, "Error", error.toString()); showErrorDialog(
context,
"Error",
error.toString(),
onDismissed: () {
_controller.resumeCamera();
}
);
return; return;
}); });
} }
Future<void> _doProcessBarcode(String barcode) async {
await processBarcode(barcode);
}
void _onViewCreated(QRViewController controller) { void _onViewCreated(QRViewController controller) {
_controller = controller; _controller = controller;
controller.scannedDataStream.listen((scandata) { controller.scannedDataStream.listen((scandata) {
_controller?.pauseCamera(); _controller?.pauseCamera();
_doProcessBarcode(scandata); processBarcode(scandata);
_controller?.resumeCamera();
}); });
} }