微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我无法向SAP服务层发出请求

如何解决我无法向SAP服务层发出请求

我想制作一个通过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),);
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。