deleteFile method

Future<bool> deleteFile({
  1. String? fileName,
  2. String? path,
})

Deletes a file on disk.

Returns true if the file did not exist or was successfully deleted, and false if the deletion failed.

Implementation

Future<bool> deleteFile({String? fileName, String? path}) async {
  final String resolved = await _resolvePath(fileName, path);
  final File file = File(resolved);
  if (!file.existsSync()) return true;
  try {
    file.deleteSync();
    return !file.existsSync();
  } on FileSystemException catch (e, s) {
    debugPrint('deleteFile failed: $e\n$s');
    return false;
  }
}