If you already have a separate package holding your images and fonts, such as a design system package, you can skip this guide.
Flutter registers an image or font declared by a package under a
packages/<package>/ prefix, and resolving it requires naming that package at the
call site. A package cannot name itself, so adding package: 'my_app' to a
resource your app declares makes it stop resolving in your app.
That means a resource declared in your app package cannot be referenced from both your app and your Widgetbook. Move it into a package that both depend on, and it gets one name that resolves in both.
If your team does not have a shared package yet, this is a good moment to create
one. Setting Widgetbook aside, a design_system package that owns your images,
fonts and theme keeps them from being copied between apps and gives you a single
place to change them. If you would rather start small, a package holding only
the assets works exactly the same way.
Create the package
Add a
pubspec.yamlnext to your images and fonts. Nodependenciesare needed.yamldesign_system/pubspec.yamlname: design_system description: > Holds the images and fonts for the app, in a separate package so they can be shared with the Widgetbook app. version: 0.0.0 publish_to: none environment: sdk: ">=3.1.0 <4.0.0" flutter: assets: - . fonts: - family: My Custom Font fonts: - asset: fonts/MyCustomFont/MyCustomFont-Regular.otf - asset: fonts/MyCustomFont/MyCustomFont-Bold.otf weight: 700Font paths are relative to the package root.
Depend on it from both packages
yamlpubspec.yamldependencies: design_system: path: design_systemyamlwidgetbook/pubspec.yamldependencies: design_system: path: ../design_systemName the package at every call site
dartImage.asset( 'images/logo.png', package: 'design_system', )dartText( label, style: const TextStyle( fontFamily: 'My Custom Font', package: 'design_system', ), )The
packageargument names the package that declares the resource, never the one referencing it, so it stays the same in your app, in your design system, and in your Widgetbook. A package that is only a transitive dependency still works.
See Fonts for font loading concerns that are not about
packaging, such as google_fonts and Flutter's default fonts.

