Skip to content

Instantly share code, notes, and snippets.

@praveenb
Forked from slightfoot/download.dart
Created June 14, 2019 16:09
Show Gist options
  • Select an option

  • Save praveenb/3dba81ebc583ef63aef133ae5dcf3dbb to your computer and use it in GitHub Desktop.

Select an option

Save praveenb/3dba81ebc583ef63aef133ae5dcf3dbb to your computer and use it in GitHub Desktop.

Revisions

  1. @slightfoot slightfoot created this gist Apr 13, 2018.
    10 changes: 10 additions & 0 deletions download.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    static var httpClient = new HttpClient();
    Future<File> _downloadFile(String url, String filename) async {
    var request = await httpClient.getUrl(Uri.parse(url));
    var response = await request.close();
    var bytes = await consolidateHttpClientResponseBytes(response);
    String dir = (await getApplicationDocumentsDirectory()).path;
    File file = new File('$dir/$filename');
    await file.writeAsBytes(bytes);
    return file;
    }