Skip to content

Add WidgetPreview and @Preview() annotation #159219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 29, 2025
Merged

Conversation

bkonyi
Copy link
Contributor

@bkonyi bkonyi commented Nov 20, 2024

This is the initial work for the upcoming Widget Preview functionality.

The WidgetPreview class allows for users to specify overrides and details to apply to its child Widget. Initially, this includes:

  • Setting arbitrary width and height constraints to mimic changes in device resolution
  • Custom text scaling factors

The Preview class is an annotation used to identify top-level, public functions as widget previews

…review() annotation

This is the initial work for the upcoming Widget Preview functionality.

The WidgetPreview widget allows for users to specify overrides and
details to apply to its child Widget. Initially, this includes:

 - Setting arbitrary width and height constraints to mimic changes in
   device resolution
 - Custom text scaling factors

The previewed widget is currently wrapped in a Material Card which
includes controls for zooming and panning within the zoomed in view.

The WidgetPreviewerWindowConstraints widget propagates the constraints
for the preview environment to each WidgetPreview widget to be used by
the WidgetPreviewWrapper widget, a SingleChildRenderObjectWidget, to force
constraints onto unconstrained children of WidgetPreview.
@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Nov 20, 2024
@bkonyi bkonyi marked this pull request as draft November 20, 2024 20:33
@bkonyi bkonyi marked this pull request as ready for review November 20, 2024 23:42
@navaronbracke
Copy link
Contributor

Is there a design doc for this new feature? I wonder if the framework should contain this source code, or if this is something that is intended for Devtools / Devtools extentions?

@bkonyi
Copy link
Contributor Author

bkonyi commented Nov 21, 2024

Is there a design doc for this new feature? I wonder if the framework should contain this source code, or if this is something that is intended for Devtools / Devtools extentions?

There's currently not a publicly shared design doc, but I think I'm going to pull one together to better communicate how this feature is going to be architected.

This particular code should live in the framework since it's meant to be included in a developer's codebase. The other components of this feature will live in the flutter tool, DevTools, and the IDE plugins.

For example, this is an early prototype showing how a widget (in this case, the root of the Flutter Gallery application) can be previewed within VSCode by applying the @Preview() annotation to a function that returns instances of WidgetPreview:

image

@bkonyi
Copy link
Contributor Author

bkonyi commented Nov 22, 2024

A design doc can be found here: #159342

@goderbauer goderbauer self-requested a review November 26, 2024 23:50
@goderbauer
Copy link
Member

@bkonyi and I talked on Friday and we had the idea that what lives in the framework would ideally be fairly minimal. Maybe just the annotation and a WidgetPreview data class.

@bkonyi bkonyi changed the title Add WidgetPreview and WidgetPreviewerWindowConstraints widgets and @Preview() annotation Add WidgetPreview and @Preview() annotation Dec 10, 2024
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@bkonyi
Copy link
Contributor Author

bkonyi commented Dec 10, 2024

@bkonyi and I talked on Friday and we had the idea that what lives in the framework would ideally be fairly minimal. Maybe just the annotation and a WidgetPreview data class.

Done, PTAL when you have a chance!

@bkonyi bkonyi requested a review from goderbauer December 10, 2024 17:40
@flutter-dashboard
Copy link

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

@bkonyi bkonyi force-pushed the initial_widget_preview branch from a8ef5e9 to f5cf3bf Compare January 28, 2025 16:38
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 28, 2025
Copy link
Contributor

auto-submit bot commented Jan 28, 2025

autosubmit label was removed for flutter/flutter/159219, because - The status or check suite Linux analyze has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 28, 2025
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 28, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 28, 2025
Copy link
Contributor

auto-submit bot commented Jan 28, 2025

autosubmit label was removed for flutter/flutter/159219, because - The status or check suite Linux analyze has failed. Please fix the issues identified (or deflake) before re-applying this label.

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 29, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jan 29, 2025
Merged via the queue into master with commit e24013a Jan 29, 2025
80 checks passed
@auto-submit auto-submit bot deleted the initial_widget_preview branch January 29, 2025 22:32
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 29, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants