writeFileIfMissing method

bool writeFileIfMissing({
  1. required String filePath,
  2. required String contents,
})

Writes contents to filePath only when the file does not exist.

Returns true when written, false when skipped.

Implementation

bool writeFileIfMissing({
  required String filePath,
  required String contents,
}) {
  final file = File(filePath);
  if (file.existsSync()) {
    return false;
  }
  file.parent.createSync(recursive: true);
  file.writeAsStringSync(contents);
  return true;
}