writeToFile method

  1. @override
void writeToFile(
  1. String path
)
override

writeToFile method writes the received file.

Implementation

@override
void writeToFile(String path) {
  // File instance is created with the given path
  final File file = File(path);

  final StringBuffer buffer = StringBuffer();
  buffer.writeln(ApprovalTestsConstants.baseHeader);
  buffer.write(content);

  // Check if the file already exists at the specific path
  if (!file.existsSync()) {
    // If the file does not exist, then it is created
    file.createSync(recursive: true);

    // After creating the file, the content is written to it
    file.writeAsStringSync(buffer.toString());
  } else {
    // If the file already exists, then the content is simply overwritten
    file.writeAsStringSync(buffer.toString());
  }
}