Visitar URL original
[cross_file] Adds support to modify files and directories by bparrishMines · Pull Request #13133 · flutter/packages · GitHub
Skip to content

[cross_file] Adds support to modify files and directories - #13133

Open
bparrishMines wants to merge 45 commits into
flutter:mainfrom
bparrishMines:cross_file_write
Open

bparrishMines wants to merge 45 commits into
flutter:mainfrom
bparrishMines:cross_file_write

Conversation

@bparrishMines

@bparrishMines bparrishMines commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Adds support for:

  • XFile.openWrite
  • XFile.writeAsString
  • XFile.delete
  • XDirectory.createFile
  • XDirectory.createDirectory
  • XDirectory.delete
  • ScopedStorageXFile.canWrite
  • ScopedStorageXDirectory.canWrite

canWrite was only added to the Scoped Storage implementation due to the inherent unreliability of using canWrite or canRead with a file system. See docs of the Java File. Scoped Storage is an exception because it is based on a permission system, so it could be valuable to check that your app has the correct permissions for a file.

This is a part of updating file_selector for flutter/flutter#193154.

file_selector_android currently has a workaround that allows for modifying a directory received from FileSelector.getDirectoryPath, so this adds writing capabilities to prevent a feature regression on Android when it starts using the latest version of cross_file.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

@bparrishMines bparrishMines changed the title Cross file write [cross_file] Adds support to modify files and directories Oct 5, 2026
@bparrishMines
bparrishMines marked this pull request as ready for review October 5, 2026 22:58
@bparrishMines bparrishMines added the CICD Run CI/CD label Oct 5, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for modifying files and directories across federated platform implementations of cross_file, introducing methods such as openWrite, writeAsString, delete, createFile, createDirectory, and canWrite. Feedback on these changes highlights several key areas for improvement: sequentially awaiting write, flush, and close operations in AndroidScopedStorageXFile.writeAsString to prevent race conditions; using a more robust method than MimeTypeMap.getFileExtensionFromUrl to extract file extensions in DocumentFileProxyApi; correcting a misleading doc comment for XDirectory.delete; and adding a recursive parameter to PlatformDirectoryDeleteParams to ensure consistent directory deletion behavior across different platforms.

Comment thread packages/cross_file/cross_file/lib/src/cross_directory.dart
Comment on lines +134 to +138
@immutable
base class PlatformDirectoryDeleteParams {
/// Constructs a [PlatformDirectoryDeleteParams];
const PlatformDirectoryDeleteParams();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Currently, PlatformDirectoryDeleteParams does not support a recursive parameter. This leads to platform inconsistencies: on Android, DocumentFile.delete() deletes directories recursively, whereas on io and darwin platforms, Directory.delete() is non-recursive by default and will fail if the directory is not empty. Adding a recursive parameter to PlatformDirectoryDeleteParams allows platform implementations to handle directory deletion consistently.

Suggested change
@immutable
base class PlatformDirectoryDeleteParams {
/// Constructs a [PlatformDirectoryDeleteParams];
const PlatformDirectoryDeleteParams();
}
@immutable
base class PlatformDirectoryDeleteParams {
/// Constructs a [PlatformDirectoryDeleteParams];
const PlatformDirectoryDeleteParams({this.recursive = false});
/// Whether to delete the directory recursively.
final bool recursive;
}

@bparrishMines bparrishMines added the federated: all_changes PR that contains changes for all packages for a federated plugin change label Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD federated: all_changes PR that contains changes for all packages for a federated plugin change p: cross_file platform-android platform-ios platform-macos platform-web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant