如何在另一个响应成功完成时触发响应?
How to trigger a response when another response done successfuly?
我正在从另一个响应的响应数据中获取 link。我怎样才能等待完成这个第一个响应?
Response responsePostImage =
await dio.get("responseLink$imgId");
var parsedPostImage = jsonDecode("$responsePostImage");
blogModel.imagePostImage =
parsedPostImage["media_details"]["sizes"]["medium"]["source_url"];
var parsedPpp = parsedPostImage["_links"]["author"];
blogModel.imagePpUrl = parsedPpp[0]["href"];
Response responseGetPp = await dio.get(blogModel.imagePp);
var parsedGetPp = jsonDecode("$responseGetPp");
blogModel.imagePp = parsedGetPp["avatar_urls"]["48"];
print(parsedGetPp["avatar_urls"]["48"]);
我想你可以检查http响应成功状态码(200)然后调用下一个api。
Response responsePostImage = await dio.get("responseLink$imgId");
if(responsePostImage.statusCode == 200) {
var parsedPostImage = jsonDecode("$responsePostImage");
blogModel.imagePostImage = parsedPostImage["media_details"]["sizes"]["medium"]["source_url"];
var parsedPpp = parsedPostImage["_links"]["author"];
blogModel.imagePpUrl = parsedPpp[0]["href"];
Response responseGetPp = await dio.get(blogModel.imagePp);
if(responseGetPp.statusCode == 200) {
var parsedGetPp = jsonDecode("$responseGetPp");
blogModel.imagePp = parsedGetPp["avatar_urls"]["48"];
print(parsedGetPp["avatar_urls"]["48"]);
}
}
我正在从另一个响应的响应数据中获取 link。我怎样才能等待完成这个第一个响应?
Response responsePostImage =
await dio.get("responseLink$imgId");
var parsedPostImage = jsonDecode("$responsePostImage");
blogModel.imagePostImage =
parsedPostImage["media_details"]["sizes"]["medium"]["source_url"];
var parsedPpp = parsedPostImage["_links"]["author"];
blogModel.imagePpUrl = parsedPpp[0]["href"];
Response responseGetPp = await dio.get(blogModel.imagePp);
var parsedGetPp = jsonDecode("$responseGetPp");
blogModel.imagePp = parsedGetPp["avatar_urls"]["48"];
print(parsedGetPp["avatar_urls"]["48"]);
我想你可以检查http响应成功状态码(200)然后调用下一个api。
Response responsePostImage = await dio.get("responseLink$imgId");
if(responsePostImage.statusCode == 200) {
var parsedPostImage = jsonDecode("$responsePostImage");
blogModel.imagePostImage = parsedPostImage["media_details"]["sizes"]["medium"]["source_url"];
var parsedPpp = parsedPostImage["_links"]["author"];
blogModel.imagePpUrl = parsedPpp[0]["href"];
Response responseGetPp = await dio.get(blogModel.imagePp);
if(responseGetPp.statusCode == 200) {
var parsedGetPp = jsonDecode("$responseGetPp");
blogModel.imagePp = parsedGetPp["avatar_urls"]["48"];
print(parsedGetPp["avatar_urls"]["48"]);
}
}