【发布时间】:2020-05-18 04:27:37
【问题描述】:
我正在构建一个类似于 instagram 的颤振应用程序,我需要从 api 加载用户个人资料图片和帖子的图像。
我已经声明了一个函数来检索.net core中用户头像的路径:
[HttpGet("{id}", Name = "Get")]
public async Task<ActionResult<string>> GetAsync(string id)
{
ApplicationUser user = _dbContext.Users.OfType<ApplicationUser>().FirstOrDefault(x => x.Id == id);
if (user == null)
return BadRequest();
return Ok(user.ProfilePicture.ToString());
}
这是我在flutter中检索图像路径的api函数:
Future<String> getUsers() async {
final response = await http.get("http://10.0.2.2:8070/api/File/07bb2a17-7cd5-471b-973a-4b77d239b6c3");
if (response.statusCode == 200) {
path=response.body.toString();
x=new File(path);
// print(response.body);
return response.body;
} else {
print(response.statusCode);
// If that call was not successful, throw an error.
throw Exception('Failed to load post');
}
}
当我尝试使用这种技术加载从 wwwroot 目录接收到的路径时:
Container(
height: 100.0,
width: 100.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: new FileImage(x),
fit: BoxFit.cover,
), ),
我收到以下错误:(操作系统错误:没有这样的文件或目录,errno = 2)
从 api 加载用户帖子和图像的正确方法是什么?
任何帮助将不胜感激。
【问题讨论】:
-
改用
Image.network小部件会更容易
标签: asp.net image api url flutter