我想制作一个通过SAP服务层搜索扫描项目的qr扫描仪,我设法使qr扫描仪正常工作,但是我无法建立与服务层的连接,我尝试使用http,请求和现在的sap库,我不是很擅长编码,这是我第一次使用flutter,另外一个问题是我无法实时调试,因为我正在通过远程桌面在mi home pc上进行编码,并且我将apk构建为测试我在哪里,
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:barcode_scan/barcode_scan.dart';
import 'package:flutter/services.dart';
import 'package:b1serviceflayer/b1serviceflayer.dart';
import 'dart:convert';
import 'items.dart';
void main() => runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
));
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
String result = "Hola!";
var itemid = '0';
Future _scanQR() async{
try{
var qrResult = await BarcodeScanner.scan();
setState(() {
result = qrResult.rawContent;
itemid = qrResult.rawContent;
Navigator.push(context, MaterialPageRoute(builder: (context) => Items(result)));
});
}
on PlatformException catch (ex) {
if(ex.code == BarcodeScanner.cameraAccessDenied){
setState(() {
result = "Permisos de Camara denegados";
});
}
else{
setState(() {
result = "Error Desconocido $ex";
});
}
}
on FormatException{
setState(() {
result = "volviste antes de escanear";
});
}
catch (ex){
setState(() {
result = "Error Desconocido $ex";
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("EScaner"),
),
body: Center(
child: Text(result, style: new TextStyle(fontSize: 30.0,fontWeight: FontWeight.bold),),
),
floatingActionButton: FloatingActionButton.extended(
icon: Icon(Icons.camera_alt),
label: Text("Escanear"),
onPressed: _scanQR,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
}
}
class Items extends StatefulWidget {
final String result;//if you have multiple values add here
Items(this.result, {Key key}): super(key: key);
@override
_ItemsState createState() => _ItemsState();
}
class _ItemsState extends State<Items> {
var resultado;
Future getData() async {
const url = "http://192.168.0.7:50001/b1s/v1/";
const user = "test";
const pwd ="test";
const companyDB ="TEST";
final b1s = B1ServiceLayer(B1Connection(serverUrl: url,
companyDB: companyDB, userName: user, password: pwd));
await b1s.loginAsync().timeout(const Duration(seconds: 10));
String itemsJson = await b1s.queryAsync("Items");
Map<String, dynamic> itemsMap = json.decode(itemsJson);
final items = itemsFromMap(itemsJson);
resultado = items;
}
@override
void initState() {
getData();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.result),
),
body: Center(
child: Text(resultado),
),
);
}
}