writeAsBytes method

Future<File?> writeAsBytes(
  1. List<int> bytes, {
  2. required BuildContext context,
  3. dynamic mode = FileMode.write,
  4. bool flush = false,
})

Calling writeAsBytes method.

FileSaver fileSaver = FileSaver(
  initialFileName:'File Name',
  fileTypes: const ['txt'],
);

fileSaver.writeAsBytes(bytes, context:context);

Implementation

Future<File?> writeAsBytes(List<int> bytes,
    {required BuildContext context,
    mode = FileMode.write,
    bool flush = false}) async {
  return filebrowser(context, this).then((path) {
    if (path != null) {
      _successMessage(context, style);
      if (File(path).existsSync()) {
        return File(path)
            .writeAsBytes(bytes, mode: FileMode.write, flush: flush);
      } else {
        return File(path).writeAsBytes(bytes, mode: mode, flush: flush);
      }
    } else {
      return null;
    }
  });
}