writeToFile function

Future<bool?> writeToFile(
  1. Uri uri, {
  2. Uint8List? bytes,
  3. String? content,
  4. FileMode? mode,
})

Convenient method to write to a file using either String or raw bytes Uint8List.

Under the hood this method calls writeToFileAsString or writeToFileAsBytes depending on which argument is passed.

If both (bytes and content) are passed, the bytes will be used and the content will be ignored.

Implementation

Future<bool?> writeToFile(
  Uri uri, {
  Uint8List? bytes,
  String? content,
  FileMode? mode,
}) {
  assert(
    bytes != null || content != null,
    '''Either [bytes] or [content] should be provided''',
  );

  return bytes != null
      ? writeToFileAsBytes(
          uri,
          bytes: bytes,
          mode: mode,
        )
      : writeToFileAsString(
          uri,
          content: content!,
          mode: mode,
        );
}