flutter
runtime_error
ai_generated
true
FlutterError: RenderBox was not laid out: RenderRepaintBoundary#12345 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
ID: flutter/render-box-intersect-error
85%Fix Rate
88%Confidence
1Evidence
2023-03-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Flutter 3.7 | active | — | — | — |
| Flutter 3.10 | active | — | — | — |
| Dart 3.0 | active | — | — | — |
Root Cause
A widget's RenderBox is accessed for geometry before it has been laid out, often due to calling RenderBox.size in initState or before the first frame.
generic中文
在 RenderBox 布局完成前访问其几何属性,通常是因为在 initState 或第一帧之前调用了 RenderBox.size。
Official Documentation
https://api.flutter.dev/flutter/rendering/RenderBox/size.htmlWorkarounds
-
85% success Delay RenderBox access until after the first frame using WidgetsBinding.instance.addPostFrameCallback and then access the GlobalKey's currentContext.size.
Delay RenderBox access until after the first frame using WidgetsBinding.instance.addPostFrameCallback and then access the GlobalKey's currentContext.size.
-
90% success Use a LayoutBuilder to get constraints and size without directly accessing RenderBox.
Use a LayoutBuilder to get constraints and size without directly accessing RenderBox.
中文步骤
Delay RenderBox access until after the first frame using WidgetsBinding.instance.addPostFrameCallback and then access the GlobalKey's currentContext.size.
Use a LayoutBuilder to get constraints and size without directly accessing RenderBox.
Dead Ends
Common approaches that don't work:
-
70% fail
SizedBox forces a size but does not ensure layout is complete before accessing RenderBox; the underlying widget may still not be laid out.
-
50% fail
addPostFrameCallback runs after the first frame, but if accessed before the callback fires, the error persists.
-
60% fail
The context may exist but the RenderBox may not be laid out yet; size is null until layout completes.