-
-
Save tundachef/7af4fd5a8e45c1c263981b11ce36d343 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class DownloadUtil { | |
static Future<String> downloadAndSaveFile(String url, String fileName) async { | |
final Directory directory = await getApplicationDocumentsDirectory(); | |
final String filePath = '${directory.path}/$fileName.png'; | |
final http.Response response = await http.get(Uri.parse(url)); | |
final File file = File(filePath); | |
await file.writeAsBytes(response.bodyBytes); | |
return filePath; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this