Skip to content

Instantly share code, notes, and snippets.

@Ivy-Walobwa
Created July 26, 2022 02:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Ivy-Walobwa/6a199bde5707962ab8a53331b9f116f5 to your computer and use it in GitHub Desktop.
Save Ivy-Walobwa/6a199bde5707962ab8a53331b9f116f5 to your computer and use it in GitHub Desktop.
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