openFileForCreate method

Future<FileInfo?> openFileForCreate({
  1. required String fileName,
  2. required Future<void> writer(
    1. File tempFile
    ),
})

Opens a file picker for the user to create a file. It suggests an fileName file name and creates a file with the contents written to the temp file by writer.

Will return a FileInfo which allows future access to the file or null if the user cancelled the file picker.

Implementation

Future<FileInfo?> openFileForCreate({
  required String fileName,
  required Future<void> Function(File tempFile) writer,
}) async {
  _logger.finest('openFilePickerForCreate($fileName)');
  return _createFileInNewTempDirectory(fileName, (tempFile) async {
    await writer(tempFile);
    final result = await _channel.invokeMapMethod<String, String>(
        'openFilePickerForCreate', {'path': tempFile.absolute.path});
    if (result == null) {
      // User cancelled.
      _logger.finer('User cancelled file picker.');
      return null;
    }
    return _resultToFileInfo(result);
  });
}