mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-29 14:06:47 +00:00
Handle barcode data passed back from the server
This commit is contained in:
parent
18ef039f4a
commit
83cc92c422
103
lib/barcode.dart
103
lib/barcode.dart
@ -57,59 +57,80 @@ Future<void> scanQrCode(BuildContext context) async {
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
} 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()}"),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
print("body: ${body.toString()}");
|
print("body: ${body.toString()}");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
// Look for an 'InvenTree' style barcode
|
|
||||||
if ((data['tool'] ?? '').toString().toLowerCase() == 'inventree') {
|
|
||||||
_handleInvenTreeBarcode(context, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unknown barcode style!
|
|
||||||
else {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
child: new SimpleDialog(
|
|
||||||
title: new Text("Unknown barcode"),
|
|
||||||
children: <Widget>[
|
|
||||||
Text("Data: $result"),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleInvenTreeBarcode(BuildContext context, Map<String, dynamic> data) {
|
void _handleBarcode(BuildContext context, Map<String, dynamic> data) {
|
||||||
|
|
||||||
final String codeType = (data['type'] ?? '').toString().toLowerCase();
|
int id;
|
||||||
|
|
||||||
final int pk = (data['id'] ?? -1) as int;
|
// A stocklocation has been passed?
|
||||||
|
if (data.containsKey('stocklocation')) {
|
||||||
|
|
||||||
if (codeType == 'stocklocation') {
|
id = data['stocklocation']['id'] ?? null;
|
||||||
|
|
||||||
// Try to open a stock location...
|
if (id != null) {
|
||||||
InvenTreeStockLocation().get(pk).then((var loc) {
|
// Try to open a stock location...
|
||||||
if (loc is InvenTreeStockLocation) {
|
InvenTreeStockLocation().get(id).then((var loc) {
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc)));
|
if (loc is InvenTreeStockLocation) {
|
||||||
}
|
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc)));
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
} else if (codeType == 'stockitem') {
|
} else if (data.containsKey('stockitem')) {
|
||||||
InvenTreeStockItem().get(pk).then((var item) {
|
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => StockDetailWidget(item)));
|
id = data['stockitem']['id'] ?? null;
|
||||||
});
|
|
||||||
} else if (codeType == 'part') {
|
if (id != null) {
|
||||||
InvenTreePart().get(pk).then((var part) {
|
InvenTreeStockItem().get(id).then((var item) {
|
||||||
Navigator.push(context,
|
Navigator.push(context, MaterialPageRoute(builder: (context) => StockDetailWidget(item)));
|
||||||
MaterialPageRoute(builder: (context) => PartDetailWidget(part)));
|
});
|
||||||
});
|
}
|
||||||
|
} else if (data.containsKey('part')) {
|
||||||
|
|
||||||
|
id = data['part']['id'] ?? null;
|
||||||
|
|
||||||
|
if (id != null) {
|
||||||
|
InvenTreePart().get(id).then((var part) {
|
||||||
|
Navigator.push(context,
|
||||||
|
MaterialPageRoute(builder: (context) => PartDetailWidget(part)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
child: SimpleDialog(
|
||||||
|
title: Text("Unknown response"),
|
||||||
|
children: <Widget>[
|
||||||
|
ListTile(
|
||||||
|
title: Text("Response data"),
|
||||||
|
subtitle: Text(data.toString()),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user