如何从 Flutter 的本地存储中删除文件?

How to delete a file from the local storage in Flutter?

实际上我想覆盖 phone 的本地存储中的文件 但它给我错误

    I/flutter ( 3835): /storage/emulated/0/Android/data/com.example.temp/files/flutter_audio_recorder_
I/flutter ( 3835): Exception: A file already exists at the path :/storage/emulated/0/Android/data/com.example.temp/files/flutter_audio_recorder_.wav

那么我怎样才能先删除这个文件呢?

我已经在这个变量中存储了 wav 文件路径 ==> var dirPath ;

创建此方法:

Future<void> deleteFile(File file) async {
  try {
    if (await file.exists()) {
      await file.delete();
    }
  } catch (e) {
    // Error in getting access to the file.
  }
}

用法:

deleteFile(File('your_file_path'));