Skip to content

Instantly share code, notes, and snippets.

@plateaukao
Created April 13, 2019 05:06
Show Gist options
  • Save plateaukao/fc07262f41bc4171e6d79fec7a1e7ce7 to your computer and use it in GitHub Desktop.
Save plateaukao/fc07262f41bc4171e6d79fec7a1e7ce7 to your computer and use it in GitHub Desktop.
download image in flutter
Future<dynamic> downloadImage() async {
String dir = (await getApplicationDocumentsDirectory()).path;
File file = new File('$dir/$filename');
if (file.existsSync()) {
print('file already exist');
var image = await file.readAsBytes();
return image;
} else {
print('file not found downloading from server');
var request = await http.get(url,);
var bytes = await request.bodyBytes;//close();
await file.writeAsBytes(bytes);
print(file.path);
return bytes;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment