[英]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
Please help请帮忙
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.