downloadAndSaveFile static method

Future<String> downloadAndSaveFile({
  1. required String url,
  2. required String fileName,
})

Implementation

static Future<String> downloadAndSaveFile({ required String url, required String fileName}) async {
  final Directory directory = await getApplicationDocumentsDirectory();
  final String filePath = '${directory.path}/$fileName';
  final http.Response response = await http.get(Uri.parse(url));
  final File file = File(filePath);
  await file.writeAsBytes(response.bodyBytes);
  return filePath;
}