downloadFile static method

Future<File> downloadFile(
  1. String url,
  2. String filename
)

Implementation

static Future<File> downloadFile(String url, String filename) async {
  var httpClient = HttpClient();

  var request = await httpClient.getUrl(Uri.parse(url));
  var response = await request.close();
  var bytes = await consolidateHttpClientResponseBytes(response);
  String? dir = await getDownloadPath();
  File file = File('$dir/$filename');
  await file.writeAsBytes(bytes);
  return file;
}