deleteDownloadedFile static method

Future<bool> deleteDownloadedFile(
  1. String fileName
)

Deletes a downloaded file with the specified fileName.

Returns true if the file was deleted, false if it didn't exist.

Implementation

static Future<bool> deleteDownloadedFile(String fileName) async {
  try {
    if (_downloadedFiles.containsKey(fileName)) {
      final filePath = _downloadedFiles[fileName]!;
      final file = File(filePath);

      if (await file.exists()) {
        await file.delete();
        _downloadedFiles.remove(fileName);
        return true;
      }
    }

    return false;
  } catch (e) {
    Error.throwWithStackTrace(
      HTTPSException(
        message: 'Failed to delete downloaded file $fileName: ${e.toString()}',
        originalError: e,
      ),
      StackTrace.current,
    );
  }
}