Im building a flutter app similar to instagram, i need to load the images of the user's profile picture and posts from the api where my backend is based on .net core c#.
I have already declared a function to retrieve the path of the user profile picture in .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());
}
and this is my api function in flutter to retrieve the path of the image:
Future<String> getUsers() async {
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');
}
}
When im trying to load the path received from the wwwroot directory using this technique: (path is like : D:\Xperience..)
Container(
height: 100.0,
width: 100.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: new FileImage(x),
fit: BoxFit.cover,
), ),
im getting the following error :(OS Error: No such file or directory, errno = 2)
What's the correct way to load user posts and images from api?
Ive been told to use Image.network but nothing is being displayed when i provide the response path in it.
Any help would be appreciated.