简体   繁体   English

我正在从快递 API 向 flutter 应用程序发送 GET 请求,但我没有收到任何 output

[英]I am sending the GET request to the flutter app from the express API but I am not getting any output

I am sending the GET request to the flutter app from the express API but I am not getting any output in the flutter App.我正在从快递 API 向 flutter 应用程序发送 GET 请求,但在 Z5ACEBC4CB70DDBB074B0AC7AZ6 中没有收到任何 output。 The API is working in the postman and I am getting the perfect output in the postman. API 在 postman 中工作,我在 Z03D476861AFCCD384510FCB81 中得到了完美的 output

快速 API。我也用过 cors 包

Please help请帮忙

来自express api的邮递员数据

我无法在颤振应用程序中获取数据

  testing() async{

debugPrint("Hello");

http.Response response = await 
http.get("http://192.168.119.97:3000/api/cricketer");
debugPrint((response.body));

debugPrint("Hello hy");
}
Future getData() async {
http.Response response = await 
http.get("http://192.168.119.97:3000/api/cricketer");
debugPrint((response.body));
data = json.decode(response.body);
debugPrint(('$data'));
setState(() {
  userData = data["cricketers"];
  debugPrint("Hello ");
  debugPrint(('$userData'));
});
   }

Calling the Function:调用 Function:

 @override
 void initState() {
 super.initState();
 getData();
 testing();
 }

  @override
  Widget build(BuildContext context) {
   return Scaffold(
     appBar: AppBar(
     title: Text("Cricketer Info"),
      backgroundColor: Colors.pink,
       ),
       body: ListView.builder(
       itemCount: userData == null ? 0 : userData.length,
        itemBuilder: (BuildContext context, int index) {
         return Card(
           child: Padding(
            padding: const EdgeInsets.all(10.0),
           child: Row(
             children: <Widget>[
              // CircleAvatar(
              //   backgroundImage: NetworkImage(userData[index][""]),
              // ),
              Padding(
                padding: const EdgeInsets.all(10.0),
                child: Text("${userData[index]["name"]}",
                  style: TextStyle(
                    fontSize: 20.0,
                    fontWeight: FontWeight.w700,
                  ),),
              )
            ],
          ),
        ),
      );
       },
     ),
   );
 }
}

I have uploaded the code also.我也上传了代码。 Please check and if possible help请检查并在可能的情况下提供帮助

First, you have to JSON decode the body for print, json.decode() gives some misleading.首先,您必须 JSON 解码正文以进行打印, json.decode() 会产生一些误导。 You can use jsonDecode(result.body) from 'dart:convert' package.您可以使用 'dart:convert' package 中的 jsonDecode(result.body)。 Here I have attached some example codes of login(Post request).在这里,我附上了一些登录(发布请求)的示例代码。 After decoding you can use a data model and factory method to convert to a dart object.解码后,您可以使用数据 model 和工厂方法转换为 dart object。

repo dart file that send post request发送 post 请求的 repo dart 文件

my data model with a factory method for decode json to dart我的数据 model 使用工厂方法将 json 解码为 dart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序帖子不起作用我没有得到输出 - app post is not working i am not getting the output 我从API获取信息,但无法使用它 - I am getting information from an API but i am not able to use it 我正在尝试通过 express 为我的 React 应用程序提供服务,为什么我会收到 404? - I'm trying to serve my react app from express, why am I getting a 404? 我在 HEROKU 应用程序中出现 CORS 错误,从 github 页面发送请求 - I am having CORS error with HEROKU app, sending a request from github page http:// localhost:3000 / api / posts我可能无法获得任何响应。 使用POSTMAN - http://localhost:3000/api/posts i am getting COULD NOT GET ANY RESPONSE. using POSTMAN 节点,快递,和尚,mongodb:发布请求后出现400错误的请求错误。 为什么会出现此错误? - Node, express, Monk, mongodb: 400 bad request error on post request. Why am I getting this error? 我正在通过ajax请求GET来表达。 但快递未收到请求 - I am requesting a GET via ajax to express. But express doesn't receive the request 运行我的快速应用程序时出现此错误 - I am getting this error when I run run my express app 为什么我在终端 Nodejs 中没有得到 output? - Why i am not getting output in teminal Nodejs? 我在 node js 中没有得到正确的输出 - I am not getting the proper output in node js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM