Skip to content

[widget_previews] [Proposal] Consider providing better errors if widget preview is unconstrained #192712

Closed

Description

@navaronbracke

Use case

People writing widget previews, that accidentally forget that a preview needs a fixed size constraint.

For example:

import 'package:flutter/widget_previews.dart';
import 'package:flutter/widgets.dart';

@Preview(name: 'Oops')
Widget buildPreview() => const Foo();

class Foo extends StatelessWidget {
  const Foo();

  @override
  Widget build(BuildContext context) {
    return SizedBox.expand(child: Text('Oops'));
  }
}

Then you get something like this in stdout of the widget previewer

The following RenderObject was being processed when the exception was fired: RenderConstrainedBox#f9f73 relayoutBoundary=up58 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
  creator: SizedBox ← Foo ← @Preview ← EnableWidgetInspectorScope ←
    WidgetPreviewTheming ← Container-[GlobalKey#9acff] ← ValueListenableBuilder<bool> ← SizedBox ←
    _WidgetPreviewWrapper ← ValueListenableBuilder<bool> ← MediaQuery ←
    ValueListenableBuilder<Brightness> ← ⋯
  parentData: <none> (can use size)
  constraints: BoxConstraints(unconstrained)
  size: MISSING
  additionalConstraints: BoxConstraints(w=Infinity, h=34.0)

Proposal

Consider intercepting errors that indicate an unconstrained size and fail with a descriptive message.

For example the following is a red flag about the unconstrained layout

  constraints: BoxConstraints(unconstrained)
  size: MISSING
  additionalConstraints: BoxConstraints(w=Infinity, h=34.0)

Activity

  1. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    c: proposalA detailed proposal for a change to Flutter
    team-toolOwned by Flutter Tool team
    on Sep 14, 2026
  2. added
    P2Important issues not at the top of the work list
    triaged-toolTriaged by Flutter Tool team
    a: widget previewsIssues related to the Widget Previewer tooling
    on Sep 18, 2026
  3. github-actions commented on Oct 16, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  4. locked as resolved and limited conversation to collaborators on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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: 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