appendTo method

void appendTo(
  1. File file, {
  2. String? content,
})

Adds an entry with name to the end of the file.

If the file does not exist, it will be created.

If content is not null, it will be added within the entry.

Implementation

void appendTo(File file, {String? content}) {
  if (!file.existsSync()) {
    file.createSync(recursive: true);
  }

  final stringBuffer = StringBuffer()
    ..writeln()
    ..writeln(_startComment);
  if (content != null) stringBuffer.writeln(content);
  stringBuffer
    ..writeln(_endComment)
    ..writeln();

  file.writeAsStringSync(
    stringBuffer.toString(),
    mode: FileMode.append,
  );
}