Skip to content

[cross_file_web] Adds support to instantiate the web PlatformXFile without needing to import web apis - #13395

Merged
auto-submit[bot] merged 26 commits into
flutter:mainfrom
bparrishMines:cross_file_web_fromBytes
Nov 9, 2026
Merged

auto-submit[bot] merged 26 commits into
flutter:mainfrom
bparrishMines:cross_file_web_fromBytes

Conversation

@bparrishMines

@bparrishMines bparrishMines commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Adds a fromBytes to WebScopedStorageXFileCreationParams so XFile can be instantiated without needing to import web APIs like fromBlob.

Adds a cross_file_web_safe.dart library that imports web_scoped_storage_cross_file_safe.dart when not compiling on web.

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

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Oct 22, 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 creating a WebScopedStorageXFile from bytes by introducing the WebScopedStorageXFileCreationParams.fromBytes factory constructor, updating the changelog, and adding integration tests. The review feedback suggests correcting a grammatical typo in the new constructor's documentation and expanding test coverage to verify behavior when fileName is null.

@bparrishMines bparrishMines changed the title add from bytes [cross_file_web] Add support for creating a web XFile with just bytes Oct 22, 2026
@bparrishMines bparrishMines changed the title [cross_file_web] Add support for creating a web XFile with just bytes [cross_file_web] Adds support to instantiate the web PlatformXFile without needing to import web apis Oct 22, 2026
@bparrishMines

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 introduces support for creating a WebScopedStorageXFile from bytes on the web, along with a platform-safe entry point (cross_file_web_safe.dart) to prevent compilation failures on non-web platforms. It adds the WebScopedStorageXFileCreationParams.fromBytes constructor, corresponding stub implementations, integration tests, and updated documentation. Feedback on the changes suggests removing the const keyword from the fromBytes constructor in the safe stub to maintain compilation consistency with the non-const factory constructor in the actual web implementation.

@bparrishMines
bparrishMines requested a review from Piinks October 29, 2026 14:50

@davidmorgan davidmorgan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The approach of a web-safe library with a conditional export looks good. Two points on the non-web stub, as line comments, plus some smaller notes:

  • The stub's WebScopedStorageXFile class is not exported by cross_file_web_safe.dart, which exports only WebScopedStorageXFileCreationParams and WebScopedStorageXFileExtension, so roughly 60 lines of the stub look unreachable. Is it needed?
  • No test exercises the stub's behaviour: the integration tests run on web and so go through the real implementation, and tests_exist_elsewhere_test.dart only checks that the import compiles on the VM.
  • In the integration test, the import alias web_safe_file refers to src/web_scoped_storage_cross_file.dart, the web-only library, which reads as if it were the safe one.
  • Minor: the stub has no fromObjectUrl, although that factory takes only a String; and testOverrides is typed dynamic. Both may be deliberate.

Not verified: CI status, and compiling the first line comment's case on both platforms; that point rests on the language rule that a sealed class cannot be instantiated.

Since it's an API addition it looks like maybe @stuartmorgan-g should also take a look?

@Piinks Piinks 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.

+1 to all of @davidmorgan's comments above. Left a few additional non-overlapping notes below on exporting CrossFileWeb and fromObjectUrl from the safe library and how the download integration test can use the web_safe import directly.

I am also still new to this area and learning, let me know if I am off the mark on some of these points. :)

@bparrishMines

Copy link
Copy Markdown
Contributor Author

@davidmorgan

  • The stub's WebScopedStorageXFile class is not exported by cross_file_web_safe.dart, which exports only WebScopedStorageXFileCreationParams and WebScopedStorageXFileExtension, so roughly 60 lines of the stub look unreachable. Is it needed?

WebScopedStorageXFile isn't needed, so I removed it and updated the test to use PlatformScopedStorageXFile.

  • No test exercises the stub's behaviour: the integration tests run on web and so go through the real implementation, and tests_exist_elsewhere_test.dart only checks that the import compiles on the VM.

Since I removed safe WebScopedStorageXFile, the stub has no real functionality, but I added tests for creation params. But in retrospect, the constructors should actually throw an error on non web platforms.

  • In the integration test, the import alias web_safe_file refers to src/web_scoped_storage_cross_file.dart, the web-only library, which reads as if it were the safe one.

Ah I missed that. I assumed Dart files weren't allowed to import the same thing twice but it look like that adding an alias overrides that.

  • Minor: the stub has no fromObjectUrl, although that factory takes only a String; and testOverrides is typed dynamic. Both may be deliberate.

This is true, but I assumed that a user wouldn't have a String objectUrl unless they were using web APIs. But it could be possible, so I added the method.

@davidmorgan davidmorgan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The updates address the earlier comments: the stub params class is now sealed, both stub factories throw UnsupportedError, the unreachable stub WebScopedStorageXFile is gone, the VM test exercises the stub, and the integration test imports the safe library. LGTM, with one CHANGELOG nit inline.

## NEXT
## 1.1.0

* Adds support for creating a `WebScopedStorageXFile` that is cross-platform safe. See

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: since the stub WebScopedStorageXFile was removed, this now reads as if a safe WebScopedStorageXFile exists. Maybe something like: "Adds WebScopedStorageXFileCreationParams.fromBytes, and cross_file_web_safe.dart, a library that can be imported on all platforms to reference CrossFileWeb and the web creation params."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a more comprehensive CHANGELOG.

@bparrishMines bparrishMines added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 9, 2026
@auto-submit
auto-submit Bot merged commit 59b7e18 into flutter:main Nov 9, 2026
13 checks passed
@bparrishMines
bparrishMines deleted the cross_file_web_fromBytes branch November 9, 2026 20:49
rmacnak-google pushed a commit to rmacnak-google/flutter that referenced this pull request Nov 10, 2026
…r#196296)

flutter/packages@565c657...08faf64

2026-11-10 [email protected] [pigeon] Pass data classes and
collections in a single buffer per native interop call
(flutter/packages#13265)
2026-11-10 [email protected] [ci] Fix release workflows
(flutter/packages#13611)
2026-11-09 [email protected] [pigeon] Fix standalone Native Interop
@FlutterApi issues (flutter/packages#13609)
2026-11-09 [email protected]
[cross_file_web] Adds support to instantiate the web PlatformXFile
without needing to import web apis (flutter/packages#13395)
2026-11-09 [email protected] Sync release-go_router-18.1.4 to
main (flutter/packages#13606)
2026-11-09 [email protected] Sync release-material_ui-1.11.0 to
main (flutter/packages#13605)
2026-11-09 [email protected] [vector_graphics_compiler] Resolve Flutter
artifact cache via package:cli_util (flutter/packages#13252)
2026-11-09 [email protected] [ci] Remove `pull_request_target`
workflows (flutter/packages#13581)
2026-11-09 [email protected] Roll Flutter from
acade0f to d463821 (1 revision) (flutter/packages#13601)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: cross_file platform-web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants