Skip to content

widget_previews: Add GroupDevicePreview #173856

@defuncart

Description

@defuncart

Use case

For the new Preview api, it would be very useful to be able to see a matrix (or group) of different resolutions for a single widget, similar to DeviceBuilder in golden_toolkit and @Preview Multi-preview Templates in Jetpack Compose.

Here is a POC using current Preview api (3.35.1):

Image

Proposal

In #166447 MultiPreview was added. GroupDevicePreview could extend this class, with an api similar to Preview:

final String? baseName;
final double? maxSize;
final List<PreviewDevice>? devices;
final double? textScaleFactor;
final WidgetWrapper? wrapper;
final PreviewTheme? theme;
final Brightness? brightness;
final PreviewLocalizations? localizations;

and would create devices.length previews (as seen in POC above).

PreviewDevice could be abstract class which users can extend, with a couple of defaults built in (i.e. PhonePortraitPreviewDevice). This class could contain name, size which GroupDevicePreview would use along with baseName, maxSize to determine name, size for the individual Previews.

I believe there is more value in having this as part of Flutter itself instead of a third-part package, similar Composable Multi-preview Templates mentioned above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: widget previewsIssues related to the Widget Previewer toolingc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions