mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Further support for QR decoding
- StockItem - Part
This commit is contained in:
parent
876aad5805
commit
d57e2033dc
@ -3,20 +3,47 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:qr_utils/qr_utils.dart';
|
import 'package:qr_utils/qr_utils.dart';
|
||||||
|
|
||||||
import 'package:InvenTree/inventree/stock.dart';
|
import 'package:InvenTree/inventree/stock.dart';
|
||||||
|
import 'package:InvenTree/inventree/part.dart';
|
||||||
|
|
||||||
import 'package:InvenTree/widget/location_display.dart';
|
import 'package:InvenTree/widget/location_display.dart';
|
||||||
|
import 'package:InvenTree/widget/part_display.dart';
|
||||||
|
import 'package:InvenTree/widget/category_display.dart';
|
||||||
|
import 'package:InvenTree/widget/stock_display.dart';
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
void scanQrCode(BuildContext context) async {
|
void scanQrCode(BuildContext context) async {
|
||||||
|
|
||||||
QrUtils.scanQR.then((String result) {
|
QrUtils.scanQR.then((String result) {
|
||||||
|
|
||||||
|
print("Scanned: $result");
|
||||||
|
|
||||||
// Look for JSON data in the result...
|
// Look for JSON data in the result...
|
||||||
final data = json.decode(result);
|
final data = json.decode(result);
|
||||||
|
|
||||||
final String tool = (data['tool'] ?? '').toString().toLowerCase();
|
// 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) {
|
||||||
|
|
||||||
// This looks like an InvenTree QR code!
|
|
||||||
if (tool == 'inventree') {
|
|
||||||
final String codeType = (data['type'] ?? '').toString().toLowerCase();
|
final String codeType = (data['type'] ?? '').toString().toLowerCase();
|
||||||
|
|
||||||
final int pk = (data['id'] ?? -1) as int;
|
final int pk = (data['id'] ?? -1) as int;
|
||||||
@ -31,22 +58,13 @@ void scanQrCode(BuildContext context) async {
|
|||||||
});
|
});
|
||||||
|
|
||||||
} else if (codeType == 'stockitem') {
|
} else if (codeType == 'stockitem') {
|
||||||
|
InvenTreeStockItem().get(pk).then((var item) {
|
||||||
}
|
Navigator.push(context, MaterialPageRoute(builder: (context) => StockItemDisplayWidget(item)));
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
child: new SimpleDialog(
|
|
||||||
title: new Text("Unknown barcode"),
|
|
||||||
children: <Widget>[
|
|
||||||
Text("Data: $result"),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
print("Scanned: $result");
|
|
||||||
});
|
});
|
||||||
|
} else if (codeType == 'part') {
|
||||||
|
InvenTreePart().get(pk).then((var part) {
|
||||||
|
Navigator.push(context,
|
||||||
|
MaterialPageRoute(builder: (context) => PartDisplayWidget(part)));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user