createFileIfNotExist function

Future<File> createFileIfNotExist(
  1. String filePath
)

Creates File in the given filePath if not exists

Implementation

Future<File> createFileIfNotExist(String filePath) async {
  final file = File(path.joinAll(path.split(filePath)));
  // existsSync is intentional: this is on the CLI startup path where blocking
  // briefly is preferable to the overhead of a microtask. Image I/O hot paths
  // use the async equivalents.
  if (!file.existsSync()) {
    await file.create(recursive: true);
  }
  return file;
}