fileflutterdartasync-awaitdart-io

dart:io sync vs async file operations


There are a number of sync and async operations for files in dart:io:

What are the considerations that I should keep in mind when choosing between the sync and async options? I seem to recall seeing somewhere that the sync option is faster if you have to wait for it to finish anyway (await file.delete() for example). But I can't remember where I saw that or if it is true.

Is there any difference between this method:

Future deleteFile(File file) async {
  await file.delete();
  print('deleted');
}

and this method:

Future deleteFile(File file) async {
  file.deleteSync();
  print('deleted');
}

Solution

  • Let me try to summarize an answer based on the comments to my question. Correct me where I'm wrong.

    Further reading