I was able to do this successfully with this code:
void getImage(String url, String userId, sessionToken) async{
var uri = Uri.parse(url);
Map body = {'Session': sessionToken, 'UserId': userId};
try {
final response = await http.post(uri,
headers: {"Content-Type": "application/json"},
body: utf8.encode(json.encode(body)));
if (response.contentLength == 0){
return;
}
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;
File file = new File('$tempPath/$userId.png');
await file.writeAsBytes(response.bodyBytes);
displayImage(file);
}
catch (value) {
print(value);
}
}
Make changes as per your requirement. Thanks..!!
I was able to do this successfully with this code:
void getImage(String url, String userId, sessionToken) async{
var uri = Uri.parse(url);
Map body = {'Session': sessionToken, 'UserId': userId};
try {
final response = await http.post(uri,
headers: {"Content-Type": "application/json"},
body: utf8.encode(json.encode(body)));
if (response.contentLength == 0){
return;
}
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;
File file = new File('$tempPath/$userId.png');
await file.writeAsBytes(response.bodyBytes);
displayImage(file);
}
catch (value) {
print(value);
}
}
Thanks for the help :)