I\'m working on a project, that requires me to download a file from URL, once a button is tapped, and store it to phone storage (probably downloads folder).
Any idea
static var httpClient = new HttpClient();
Future _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;
}