Visitar URL original
[file_selector] Updates `cross_file` to `0.4.0` and updates to platform interface to latest standard by bparrishMines · Pull Request #13147 · flutter/packages · GitHub
Skip to content

[file_selector] Updates cross_file to 0.4.0 and updates to platform interface to latest standard - #13147

Open
bparrishMines wants to merge 47 commits into
flutter:mainfrom
bparrishMines:file_selector_2
Open

bparrishMines wants to merge 47 commits into
flutter:mainfrom
bparrishMines:file_selector_2

Conversation

@bparrishMines

@bparrishMines bparrishMines commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Because file_selector exports cross_file, a breaking change is needed to update the dependency. Since a breaking change is needed anyway, this also removes deprecated methods and API and adds support for XDirectorys.

List of changes in the platform interface (also included in CHANGELOG.md):

  • Updates cross_file dependency to 0.4.0.
  • Removes MethodChannel implementation.
  • Replaces FileSelectorPlatform's of implementation PlatformInterface with the base keyword.
  • Changes openFile and openFiles to take a OpenDialogOptions.
  • Removes getSavePath. Replaced by getSaveLocation.
  • Changes getSaveLocation to take a SaveLocationOptions.
  • Replaces FileSaveLocation.path with FileSaveLocation.file.
  • Replaces getDirectoryPath with getDirectory and now returns a XDirectory.
  • Replaces getDirectoryPaths with getDirectories and now returns List<XDirectory.
  • Removes XTypeGroup.macUTIs. Use XTypeGroup.uniformTypeIdentifiers instead.

Every platform functionally remains the same except for Android. Android no longer copies a file a content provider to a temporary directory. It now only returns the original content URIs for files and directories. cross_file now handles using those file directly.

Part of flutter/flutter#193154

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 File selector 2 [file_selector] Updates cross_file to 0.4.0 and update to platform interface to standard Oct 6, 2026
@bparrishMines
bparrishMines marked this pull request as ready for review October 6, 2026 19:31
@bparrishMines bparrishMines added the CICD Run CI/CD label Oct 6, 2026
@bparrishMines bparrishMines changed the title [file_selector] Updates cross_file to 0.4.0 and update to platform interface to standard [file_selector] Updates cross_file to 0.4.0 and updates to platform interface to latest standard Oct 6, 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 updates the file_selector plugin and its platform implementations to version 3.0.0 of the file_selector_platform_interface, including an update to cross_file 0.4.0. The API has been refactored to use OpenDialogOptions and SaveLocationOptions, and directory selection methods have been renamed to getDirectory and getDirectories. Example applications have been updated to reflect these API changes. Feedback was provided regarding a potential malformed URI in the macOS example, a missing dispose method for a ScrollController in the text display example, and a fragile URI parsing implementation in the Android example.

Comment thread packages/file_selector/file_selector_macos/example/lib/save_text_page.dart Outdated
} else if (entity is XDirectory) {
// Getting a name for a directory is not supported, so this is a
// workaround to show just the directory name.
entityNames.add(entity.uri.split('%2F').last);

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

Splitting the URI string by '%2F' is fragile and will fail to extract the directory name if the URI is a standard file path (using / or \) or a standard file URI. A more robust approach is to parse the URI and extract the last path segment, handling both / and %2F safely.

Suggested change
entityNames.add(entity.uri.split('%2F').last);
final String? lastSegment = Uri.parse(entity.uri).pathSegments.lastOrNull;
entityNames.add(lastSegment?.split('/').lastOrNull ?? entity.uri);

@bparrishMines

Copy link
Copy Markdown
Contributor Author

@loic-sharma Can you review the changes to file_selector_platform_interface and file_selector before I request reviews for platform implementations?

@bparrishMines bparrishMines added the federated: all_changes PR that contains changes for all packages for a federated plugin change label Oct 7, 2026
@chrisbobbe

Copy link
Copy Markdown

Does this PR fix flutter/flutter#141002? It looks like it might.

That issue is an OutOfMemoryError when picking large files on Android, because the plugin read each picked file entirely into memory and sent the bytes to Dart. This PR deletes that code. (That also removes the cursor.getInt size read, which can't represent sizes over 2 GB.)

As stuartmorgan-g wrote on that issue:

The correct solution is an abstraction that allows streaming directly from the source, as mentioned in my earlier comment.

With this PR, openFile/openFiles return the content URIs as XFile.scopedStorage, and on Android, cross_file_android's openRead streams those through ContentResolver.openInputStream, in 4 KiB chunks.

So picking no longer reads the whole file up front, which looks like exactly that abstraction. If so, maybe the description could say this fixes flutter/flutter#141002 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants