Created
April 13, 2019 05:06
-
-
Save plateaukao/fc07262f41bc4171e6d79fec7a1e7ce7 to your computer and use it in GitHub Desktop.
download image in flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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