writeToFileAsBytes function

Future<bool?> writeToFileAsBytes(
  1. Uri uri, {
  2. required Uint8List bytes,
  3. FileMode? mode,
})

Write to a file.

  • uri is the URI of the file.
  • bytes is the content of the document as a list of bytes Uint8List.
  • mode is the mode in which the file will be opened for writing. Use FileMode.write for truncating and FileMode.append for appending to the file.

Returns true if the file was successfully written to.

Implementation

Future<bool?> writeToFileAsBytes(
  Uri uri, {
  required Uint8List bytes,
  FileMode? mode,
}) async {
  final writeMode =
      mode == FileMode.append || mode == FileMode.writeOnlyAppend ? 'wa' : 'wt';

  final args = <String, dynamic>{
    'uri': '$uri',
    'content': bytes,
    'mode': writeMode,
  };

  return kDocumentFileChannel.invokeMethod<bool>('writeToFile', args);
}