我想使库存管理系统变得扑朔迷离。我想扫描手机上的条形码,如果与我的产品条形码(一直在剩余api Json值中)匹配,它将返回我“是的,在这里输入您的产品并返回此产品名称,价格等。
我可以使用以下代码访问rest api:
int _stokSayisi;
int get stokSayisi => _stokSayisi;
List<Stok> _stokListesi;
List<Stok> get stokListesi => _stokListesi;
Future<List<Stok>> getStok() async {
final String token = token_manager.token;
return await http.get("http://192.168.1.29:7070/api/v2/Items", headers: {
HttpHeaders.authorizationHeader: "Bearer $token"
}).then((response) {
var dataList = json.decode(response.body)["Data"] as List;
print("Stok Sayısı -> "+ dataList.length.toString());
_stokSayisi = dataList.length;
_stokListesi = dataList.map<Stok>((json) => Stok.fromJson(json)).toList();
});
}
,并且ı可以达到这样的产品条形码编号(getStok.dart):
Widget createListView(BuildContext context, AsyncSnapshot snapshot) {
return new ListView.builder(
itemCount: get_stok.stokSayisi,
itemBuilder: (BuildContext context, int index) {
return new Column(
children: <Widget>[
new ListTile(
title:
new Text(get_stok.stokListesi[index].stokTemelBilgi.stokAdi),
subtitle:
new Text(get_stok.stokListesi[index].stokTemelBilgi.barkodNum),//Here is my barcodeNumber value.But ı cannot understand how to validate this value with scanned code value//.
)
],
);
},
);
}
这是我的BarCodeScanner.dart :(我想用我的带有注释括号的getStok.dart类来验证_reader值。)
class _BarcodeScanState extends State<BarcodeScan> {
String _reader = '';
Permission permission = Permission.Camera;
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text("Stok Barkod Okuma"),
backgroundColor: Colors.redAccent,
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
/*new Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
),*/
new RaisedButton(
//splashColor: Colors.pinkAccent,
color: Colors.black,
child: new Text(
"BARKOD OKUT",
style: new TextStyle(fontSize: 30.0, color: Colors.white),
),
onPressed: scan,
),
new Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
),
new Text('$_reader',
softWrap: true,
style: new TextStyle(fontSize: 30.0, color: Colors.blue))
],
))),
);
}
requestPermission() async {
void result = await SimplePermissions.requestPermission(permission);
}
scan() async {
try {
String reader = await BarcodeScanner.scan();
if (!mounted) {
return;
}
setState(() {
_reader = reader;
});
} on PlatformException catch (e) {
if (e.code == BarcodeScanner.CameraAccessDenied) {
requestPermission();
} else {
setState(() {
_reader = "unknown error $e";
});
}
} on FormatException {
setState(() {
_reader = "User exit without scanning";
});
}
}
}