downloadFile static method

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

Implementation

static Future<File?> downloadFile(String url, String fileName) async {
  try {
    return await httpClient.getUrl(Uri.parse(url)).then((value) async {
      return value.close().then((response) async {
        return await consolidateHttpClientResponseBytes(response)
            .then((bytes) async {
          return await _localFile.then((file) async {
            return await file.writeAsBytes(bytes);
          }).catchError((onError) => throw ("Error 1"));
        }).catchError((onError) => throw ("Error 2"));
      }).catchError((onError) => throw ("Error 3"));
    }).catchError((onError) => throw ("Error 4"));
  } catch (error) {
    return Future.value(null);
  }
}