Skip to content

[cross_file] Updates cross_file to a package separated federated plugin #11010

Open
bparrishMines wants to merge 362 commits into
flutter:mainfrom
bparrishMines:new_crossfile
Open

[cross_file] Updates cross_file to a package separated federated plugin #11010
bparrishMines wants to merge 362 commits into
flutter:mainfrom
bparrishMines:new_crossfile

Conversation

@bparrishMines

@bparrishMines bparrishMines commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Updates cross_file to a package separated federated plugin. Keeping the package separation is still debatable.

Follows the general design outlined at https://flutter.dev/go/flutter-file-system

Fixes flutter/flutter#91869

Implementation is split into

Pubspec dependencies have been changed to use ones from git to have runnable example apps while in development and review. Specifically because file_selector uses the current version of cross_file and I didn't want to make this a file_selector + cross_file PR. Can update it to this if preferred.

The reason file_selector is different for the example apps is because I wanted to ensue Android, iOS, macOS still work without copying the file to a file with the Apps sandbox.

Example

dependencies:
  cross_file:
    git:
      url: https://github.com/bparrishMines/packages
      ref: new_crossfile
      path: packages/cross_file/cross_file
  file_selector:
    git:
      url: https://github.com/bparrishMines/packages
      ref: new_file_selector
      path: packages/file_selector/file_selector

The cross_file example will run for all platforms.

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 3

@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 17, 2026
@bparrishMines bparrishMines added the CICD Run CI/CD label Jun 17, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 17, 2026
@bparrishMines bparrishMines added the CICD Run CI/CD label Jun 17, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 23, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 23, 2026
assets:
- assets/hello.txt

dependency_overrides:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is this an override and not the actual dependency?


/// The common superclass for [XFile] and [XDirectory].
@immutable
class XEntity {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this maybe XFilesystemEntity to make it clearer what it's for and less likely to collide with other things? That would also be consistent with the Dart IO class names.

@internal
final PlatformXEntity platform;

/// A string used to reference the resource's location.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: "identifier" rather than "location", since we are using the term "uri".

/// Provides a nonnull platform class extension.
///
/// Will throw an exception if the specified platform extension can not be
/// returned.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've been thinking about this more; under what circumstances would this be safe to call? It's up to the platform implementation what extension (if any) to return, and that's an implementation detail of the platform, so clients shouldn't rely on knowing it.

Should we just have S? getExtension?

/// the resource.
Future<Uint8List> readAsBytes() => platform.readAsBytes();

/// Reads the entire resource contents as a string using the given Encoding.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Encoding]

@override
Stream<Uint8List> openRead([int? start, int? end]) {
assert(start == null || start >= 0);
assert(end == null || end >= (start ?? 0));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Don't these need to throw ArgumentError, rather than just assert in debug?

void dataReceivedHandler(NSData data) {
final Uint8List bytes = _extractBytesToUint8List(data);

runOnPlatformThread(() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

TODO to remove these once thread merging is non-optional on macOS?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Actually, wait, does this code work on macOS without thread merging? It looks like this is being used to make the Dart code run on the Dart main isolate's thread, which isn't going to be the platform thread in that case.

Maybe we can't implement this code with FFI yet after all?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a CONTRIBUTING.md explaining the use of this, as in path_provider_foundation.

`XFile` on the web platform is backed by [Blob](https://api.dart.dev/be/180361/dart-html/Blob-class.html)
objects and their URLs.

It seems that Safari hangs when reading Blobs larger than 4GB (your app will stop without returning

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Isn't this (and the related next paragraph) no longer applicable to this version of the package?


[![Data on Global support for Blob URLs](https://caniuse.bitsofco.de/image/bloburls.png)](https://caniuse.com/bloburls)

### Tests

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should move to a CONTRIBING.md

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.

[cross_file] Platform-aware factories.

3 participants