Skip to content

Commit b3aeefb

Browse files
authored
[Widget Preview] Provide descriptive error when widget preview is unconstrained (flutter#193005)
## Description When a developer previews a widget that expects finite parent constraints (such as `SizedBox.expand` or expanding flex layouts), the preview scaffold previously crashed with cryptic `BoxConstraints forces an infinite width/height` assertions and secondary cascading failures (such as `hasSize` assertions and semantics traversal errors). This PR improves the error handling when previews are rendered under unconstrained dimensions: - Intercepts unconstrained layout errors in the scaffold's `FlutterError.onError` handler and presents a structured `FlutterError` explaining that previews are unconstrained by default and directing developers to `@Preview(size: Size(width, height))` or explicit wrapper dimensions. - Traps layout exceptions at the preview card boundary (`_WidgetPreviewWrapperBox`), preventing secondary layout, paint, or semantics assertion cascades. - Renders `WidgetPreviewErrorWidget` locally for the affected preview card so the rest of the preview environment remains interactive. ## Related Issue Fixes flutter#192712 ## Tests - Added regression test in `dev/integration_tests/widget_preview_scaffold/test/error_widget_test.dart`.
1 parent dddb028 commit b3aeefb

3 files changed

Lines changed: 862 additions & 214 deletions

File tree

0 commit comments

Comments
 (0)