writeAsString method

  1. @override
FutureOr<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
FutureOr<void> writeAsString(
  String contents, {
  required String extension,
  Encoding encoding = utf8,
}) async {
  final Uri outputUri = _getOutputUri(extension);
  final File file = File.fromUri(outputUri);
  await file.writeAsString(contents, encoding: encoding);
  _outputs.add(outputUri);
}