Skip to content

Commit de2514c

Browse files
Document reasoning for why CustomMultiChildLayout size can't depend on children and how to do it (flutter#47797)
1 parent a1bf03f commit de2514c

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

packages/flutter/lib/src/rendering/custom_layout.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ class MultiChildLayoutParentData extends ContainerBoxParentData<RenderBox> {
2929
/// given the previous instance.
3030
///
3131
/// Override [getSize] to control the overall size of the layout. The size of
32-
/// the layout cannot depend on layout properties of the children.
32+
/// the layout cannot depend on layout properties of the children. This was
33+
/// a design decision to simplify the delegate implementations: This way,
34+
/// the delegate implementations do not have to also handle various intrinsic
35+
/// sizing functions if the parent's size depended on the children.
36+
/// If you want to build a custom layout where you define the size of that widget
37+
/// based on its children, then you will have to create a custom render object.
38+
/// See [MultiChildRenderObjectWidget] with [ContainerRenderObjectMixin] and
39+
/// [RenderBoxContainerDefaultsMixin] to get started or [RenderStack] for an
40+
/// example implementation.
3341
///
3442
/// Override [performLayout] to size and position the children. An
3543
/// implementation of [performLayout] must call [layoutChild] exactly once for

packages/flutter/lib/src/widgets/basic.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ class LayoutId extends ParentDataWidget<CustomMultiChildLayout> {
19551955
/// the children.
19561956
///
19571957
/// [CustomMultiChildLayout] is appropriate when there are complex relationships
1958-
/// between the size and positioning of a multiple widgets. To control the
1958+
/// between the size and positioning of multiple widgets. To control the
19591959
/// layout of a single child, [CustomSingleChildLayout] is more appropriate. For
19601960
/// simple cases, such as aligning a widget to one or another edge, the [Stack]
19611961
/// widget is more appropriate.

0 commit comments

Comments
 (0)