Skip to content

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

@bkonyi

Description

@bkonyi

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: widget previewsIssues related to the Widget Previewer toolingteam-toolOwned by Flutter Tool teamtriaged-toolTriaged by Flutter Tool team

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions