Skip to content

Instantly share code, notes, and snippets.

@tundachef
Forked from Ivy-Walobwa/download-util.dart
Created August 18, 2022 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tundachef/7af4fd5a8e45c1c263981b11ce36d343 to your computer and use it in GitHub Desktop.
Save tundachef/7af4fd5a8e45c1c263981b11ce36d343 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;
}
}
@tundachef
Copy link
Author

Thanks for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment