createFile function

Future<DocumentFile?> createFile(
  1. Uri parentUri, {
  2. required String mimeType,
  3. required String displayName,
  4. Uint8List? bytes,
  5. String content = '',
})

Convenient method to create files using either String or raw bytes Uint8List.

Under the hood this method calls createFileAsString or createFileAsBytes 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<DocumentFile?> createFile(
  Uri parentUri, {
  required String mimeType,
  required String displayName,
  Uint8List? bytes,
  String content = '',
}) {
  return bytes != null
      ? createFileAsBytes(
          parentUri,
          mimeType: mimeType,
          displayName: displayName,
          bytes: bytes,
        )
      : createFileAsString(
          parentUri,
          mimeType: mimeType,
          displayName: displayName,
          content: content,
        );
}