Skip to content

[cross_file] Platform-aware factories. #91869

Closed
flutter/packages
#11010

Description

@ditman

The current implementation of cross_file relies on cross-platform constructors that "need to work" across all platforms. With time, and as features are added, these constructors end up growing, and now some parameters are being ignored by some platforms and used by others. This causes confusion/problems.

It seems that cross-platform constructors are not the way to go for this particular package; instead XFile users should be able to choose what factory they need for the platform that they're implementing. So, in places where dart:io is available, they could do:

XFileIO.fromFile(io.File file) or XFileIO.fromPath(String path)

But if dart:html is available

XFileWeb.fromHtmlFile(html.File file) or XFileWeb.fromBlob(html.Blob blob, String name) or XFileWeb.fromBlobUrl(String blobUrl, String name, int length...)...

or any other "specialty" constructors that would make sense per platform.

The XFile class that most people use would end up being a read-only interface to retrieve data from the file, and the different backing implementations would extend it.

(This would also allow us to return XFile as the base-class name for all the objects, instead of being the top-most classname, which is weird from an OOP standpoint!)

Some questions:

  • What to do when the user wants to modify the contents of a file programmatically?
  • How to perform those operations so the modified file still uses an efficient backend?
  • Should we keep an "inefficient" Uint8List-backed constructor so people can build raw files from memory?

Activity

  1. added
    c: new featureNothing broken; request for a new capability
    P3Issues that are less important to the Flutter project
    on Oct 15, 2021
  2. ditman commented on Oct 15, 2021

    @ditman
    MemberAuthor

    @stuartmorgan said:

    I think we could make it relatively painless if we:

    • Add new constructors with the APIs we want, and comment (but don't actively deprecate) the old APIs as being soft-deprecated
    • Update all our plugins to use the new APIs
    • Give the ecosystem a little while to catch up
    • At some point deprecated the old constructors
    • Eventually remove them in a breaking change
  3. Jjagg commented on Dec 30, 2021

    @Jjagg
    Contributor

    I ran into a pretty serious limitation caused by this issue.

    Because XFile does not have a Blob constructor for web, it can't refer to a file on the user's machine. And without a Blob, there's no way to get the data in the file back from the XFile. So, currently, the only way to pass the file data in an XFile is by reading the full file into memory and passing the Uint8List in the constructor.
    I ran into this with a drag and drop implementation for web.

  4. ditman commented on Jan 5, 2022

    @ditman
    MemberAuthor

    @Jjagg yes, having a Blob constructor on the web is my main motivation for this change. The current web version loads a file, internally stores its blob URL, and then it attempts to re-hydrate the Blob when reading data from it. It should just... store the File/Blob and be done with it.

  5. added
    packageflutter/packages repository. See also p: labels.
    and removed on Mar 6, 2023
  6. 22 remaining items

  7. added
    📜Issue was posted to Discord. Remove to have the issue reannounced. (For "design doc", "emergency")
    on Apr 10, 2026
  8. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Aug 14, 2026
  9. flutter-triage-bot commented on Aug 14, 2026

    @flutter-triage-bot

    This design doc is assigned to @bparrishMines but has had no recent status updates. If the proposal has been deferred, please consider unassigning thes issue. Alternatively, if the design doc has been abandoned, please close the issue. This allows people to have a clearer picture of what work is actually planned. Thanks!

  10. bparrishMines commented on Aug 20, 2026

    @bparrishMines
    Contributor

    This is still being worked on in flutter/packages#11010

  11. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on Aug 20, 2026
  12. github-actions commented on Oct 8, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  13. locked as resolved and limited conversation to collaborators on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

📜Issue was posted to Discord. Remove to have the issue reannounced. (For "design doc", "emergency")P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilitydesign docTracks a design discussion documentp: cross_fileThe cross_file pluginpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions