writeAsString method

  1. @override
Future<void> writeAsString(
  1. String contents, {
  2. required String extension,
  3. Encoding encoding = utf8,
})
override

Writes contents to a text file with the specified extension using the given encoding.

Returns a Future that completes after writing the asset out.

  • Throws an error if the output was not valid (that is, the resulting file extension is not in allowedExtensions)

NOTE: Most Builder implementations should not need to await this Future since the runner will be responsible for waiting until all outputs are written.

@param contents The text content to write @param extension The extension of the file to be written (must be in allowedExtensions) @param encoding The character encoding to use (defaults to UTF-8)

Implementation

@override
Future<void> writeAsString(
  String contents, {
  required String extension,
  Encoding encoding = utf8,
}) async {
  assert(
    encoding == utf8,
    'Only utf8 encoding is supported for deferred outputs',
  );
  assert(
    outputUri == asset.uriWithExtension(extension),
    'Unexpected output uri, expected $outputUri',
  );
  _buffer.writeln(contents);
}