createFileOfPdfUrl method

Future<File> createFileOfPdfUrl({
  1. required String imgPath,
})

Implementation

Future<File> createFileOfPdfUrl({required String imgPath}) async {
  debugPrint("Img path : $imgPath");
  Completer<File> completer = Completer();
  // print("Start download file from internet!");
  try {
    final url = imgPath;
    final filename = url.substring(url.lastIndexOf("/") + 1);
    var request = await HttpClient().getUrl(Uri.parse(url));
    var response = await request.close();
    var bytes = await consolidateHttpClientResponseBytes(response);
    var dir = await getApplicationDocumentsDirectory();
    // print("Download files");
    // print("${dir.path}/$filename");
    File file = File("${dir.path}/$filename");

    await file.writeAsBytes(bytes, flush: true);
    completer.complete(file);
  } catch (e) {
    throw Exception('Error parsing asset file!');
  }
  return completer.future;
}