Skip to content

[ Widget Preview ] Fix crash when @Preview annotations appeared outside of lib/#180768

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
bkonyi:widget_preview_previews_in_test
Jan 19, 2026
Merged

[ Widget Preview ] Fix crash when @Preview annotations appeared outside of lib/#180768
auto-submit[bot] merged 5 commits into
flutter:masterfrom
bkonyi:widget_preview_previews_in_test

Conversation

@bkonyi

@bkonyi bkonyi commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

The widget preview scaffold requires that previews are defined within importable libraries. Since Dart does not support absolute paths for imports or relative imports outside of the project, it's not possible for the widget previewer to display previews defined outside of lib/.

This change updates the preview detector to ignore libraries that don't have a package name (e.g., libraries under test/) and updates packageName properties to not allow for null to make it clear that package names are required for previews.

Fixes #178651

…side of `lib/`

The widget preview scaffold requires that previews are defined within
importable libraries. Since Dart does not support absolute paths for
imports or relative imports outside of the project, it's not possible
for the widget previewer to display previews defined outside of `lib/`.

This change updates the preview detector to ignore libraries that don't
have a package name (e.g., libraries under `test/`) and updates `packageName`
properties to not allow for null to make it clear that package names are
required for previews.

Fixes flutter#178651
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jan 9, 2026
@bkonyi bkonyi requested a review from jyameo January 9, 2026 19:57

@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 correctly fixes a crash that occurs when @Preview annotations are used outside of the lib/ directory. The approach of making packageName non-nullable and ignoring libraries without a package name is sound. The changes are consistent across the codebase, including templates, and a new test case has been added to verify the fix. I have one high-severity comment regarding a potential inconsistency in the test utilities that could lead to test failures.

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

Overall lgtm! However seems there are some CI test failures, PTAL

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 19, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 19, 2026
@auto-submit

auto-submit Bot commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/180768, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 19, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jan 19, 2026
Merged via the queue into flutter:master with commit b74475a Jan 19, 2026
151 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 23, 2026
flutter-zl pushed a commit to flutter-zl/flutter that referenced this pull request Feb 10, 2026
…side of `lib/` (flutter#180768)

The widget preview scaffold requires that previews are defined within
importable libraries. Since Dart does not support absolute paths for
imports or relative imports outside of the project, it's not possible
for the widget previewer to display previews defined outside of `lib/`.

This change updates the preview detector to ignore libraries that don't
have a package name (e.g., libraries under `test/`) and updates
`packageName` properties to not allow for null to make it clear that
package names are required for previews.

Fixes flutter#178651
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ Widget Preview ] @Preview() applications outside of lib/ cause the previewer to crash

2 participants