mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Yay, barcode scanning working again!!!
This commit is contained in:
parent
a4390d16d9
commit
baed2d98c6
@ -53,6 +53,63 @@ class _QRViewState extends State<InvenTreeQRView> {
|
|||||||
|
|
||||||
print("Response:");
|
print("Response:");
|
||||||
print(response.body);
|
print(response.body);
|
||||||
|
|
||||||
|
if (response.statusCode != 200) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
child: new SimpleDialog(
|
||||||
|
title: Text("Server Error"),
|
||||||
|
children: <Widget>[
|
||||||
|
ListTile(
|
||||||
|
title: Text("Error ${response.statusCode}"),
|
||||||
|
subtitle: Text("${response.body.toString().split("\n").first}"),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode the response
|
||||||
|
final Map<String, dynamic> body = json.decode(response.body);
|
||||||
|
|
||||||
|
// "Error" contained in response
|
||||||
|
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>'}"),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else if (body.containsKey('success')) {
|
||||||
|
// Decode the barcode!
|
||||||
|
// Ideally, the server has returned unto us something sensible...
|
||||||
|
_handleBarcode(context, body);
|
||||||
|
} else {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
child: new SimpleDialog(
|
||||||
|
title: Text("Unknown response"),
|
||||||
|
children: <Widget>[
|
||||||
|
ListTile(
|
||||||
|
title: Text("Response data"),
|
||||||
|
subtitle: Text("${body.toString()}"),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}).timeout(
|
}).timeout(
|
||||||
Duration(seconds: 5)
|
Duration(seconds: 5)
|
||||||
).catchError((error) {
|
).catchError((error) {
|
||||||
@ -63,10 +120,16 @@ class _QRViewState extends State<InvenTreeQRView> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
processBarcode(scandata);
|
_controller?.pauseCamera();
|
||||||
|
_doProcessBarcode(scandata);
|
||||||
|
_controller?.resumeCamera();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,6 +270,7 @@ void _handleBarcode(BuildContext context, Map<String, dynamic> data) {
|
|||||||
if (pk != null) {
|
if (pk != null) {
|
||||||
InvenTreeStockLocation().get(context, pk).then((var loc) {
|
InvenTreeStockLocation().get(context, pk).then((var loc) {
|
||||||
if (loc is InvenTreeStockLocation) {
|
if (loc is InvenTreeStockLocation) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc)));
|
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -220,6 +284,7 @@ void _handleBarcode(BuildContext context, Map<String, dynamic> data) {
|
|||||||
|
|
||||||
if (pk != null) {
|
if (pk != null) {
|
||||||
InvenTreeStockItem().get(context, pk).then((var item) {
|
InvenTreeStockItem().get(context, pk).then((var item) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => StockDetailWidget(item)));
|
Navigator.push(context, MaterialPageRoute(builder: (context) => StockDetailWidget(item)));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -231,8 +296,8 @@ void _handleBarcode(BuildContext context, Map<String, dynamic> data) {
|
|||||||
|
|
||||||
if (pk != null) {
|
if (pk != null) {
|
||||||
InvenTreePart().get(context, pk).then((var part) {
|
InvenTreePart().get(context, pk).then((var part) {
|
||||||
Navigator.push(context,
|
Navigator.of(context).pop();
|
||||||
MaterialPageRoute(builder: (context) => PartDetailWidget(part)));
|
Navigator.push(context, MaterialPageRoute(builder: (context) => PartDetailWidget(part)));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// TODO - Show an error here!
|
// TODO - Show an error here!
|
||||||
|
@ -382,6 +382,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
Spacer(),
|
Spacer(),
|
||||||
|
*/
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
@ -404,7 +405,6 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
*/
|
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user