flutter / flutter/flutter

Add support for loading assets with non-package paths in `dart:ui` APIs

Open
#171,284 0 comments 0 reactions 0 assignees View on GitHub
a: widget previews P2 team-tool triaged-tool
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

When assets are loaded by `package:flutter` APIs, they rely on the current `AssetBundle` to determine how to load the assets. The widget previewer currently wraps each preview in a `DefaultAssetBundle` widget with a custom `PreviewAssetBundle`, which converts project-relative asset paths into package asset paths. This is done as the widget preview scaffold project imports the projects containing previews and packages their assets using the package asset path scheme.

For example, for a preview defined in a project named `package_name`:

`/assets/bar.png` -> `packages/package_name/assets/bar.png`

Unfortunately, since `AssetBundle` and `DefaultAssetBundle` are part of the framework and not `dart:ui`, providing a custom `AssetBundle` does not override the behavior of asset loading for `dart:ui` APIs. This means that project-relative asset paths provided to these APIs will not resolve correctly (package asset paths will continue to work as expected).

At time of writing, the following APIs are currently impacted:

- [`FragmentProgram.fromAsset`](https://api.flutter.dev/flutter/dart-ui/FragmentProgram/fromAsset.html)
- [`ImmutableBuffer.fromAsset`](https://api.flutter.dev/flutter/dart-ui/ImmutableBuffer/fromAsset.html)
- [`ShaderLibrary.fromAsset`](https://api.flutter.dev/flutter/flutter_gpu/ShaderLibrary/fromAsset.html)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.