@@ -25,6 +25,10 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
2525 final bool debugShowZIndex;
2626 final bool debugShowChildDepth;
2727
28+ // fixed size、matchParent(wrapContent is not supported yet)
29+ final double width;
30+ final double height;
31+
2832 ConstraintLayout ({
2933 Key ? key,
3034 this .childConstraints,
@@ -38,6 +42,8 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
3842 this .debugName,
3943 this .debugShowZIndex = false ,
4044 this .debugShowChildDepth = false ,
45+ this .width = matchParent,
46+ this .height = matchParent,
4147 }) : super (
4248 key: key,
4349 children: children,
@@ -46,6 +52,8 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
4652 @override
4753 RenderObject createRenderObject (BuildContext context) {
4854 assert (_debugEnsureNotEmptyString ('debugName' , debugName));
55+ assert (width >= 0 || width == matchParent);
56+ assert (height >= 0 || height == matchParent);
4957 return _ConstraintRenderBox ()
5058 ..childConstraints = childConstraints
5159 .._debugShowGuideline = debugShowGuideline
@@ -56,7 +64,9 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
5664 .._releasePrintLayoutTime = releasePrintLayoutTime
5765 .._debugName = debugName
5866 .._debugShowZIndex = debugShowZIndex
59- .._debugShowChildDepth = debugShowChildDepth;
67+ .._debugShowChildDepth = debugShowChildDepth
68+ .._width = width
69+ .._height = height;
6070 }
6171
6272 @override
@@ -65,6 +75,8 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
6575 covariant RenderObject renderObject,
6676 ) {
6777 assert (_debugEnsureNotEmptyString ('debugName' , debugName));
78+ assert (width >= 0 || width == matchParent);
79+ assert (height >= 0 || height == matchParent);
6880 (renderObject as _ConstraintRenderBox )
6981 ..childConstraints = childConstraints
7082 ..debugShowGuideline = debugShowGuideline
@@ -75,7 +87,9 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
7587 ..releasePrintLayoutTime = releasePrintLayoutTime
7688 ..debugName = debugName
7789 ..debugShowZIndex = debugShowZIndex
78- ..debugShowChildDepth = debugShowChildDepth;
90+ ..debugShowChildDepth = debugShowChildDepth
91+ ..width = width
92+ ..height = height;
7993 }
8094}
8195
@@ -98,8 +112,9 @@ List<Widget> constraintGrid({
98112}) {
99113 assert (itemCount > 0 );
100114 assert (columnCount > 0 );
101- assert (itemWidth == null || (itemWidth > 0 || itemWidth == wrapContent));
102- assert (itemHeight == null || (itemHeight > 0 || itemHeight == wrapContent));
115+ assert (itemWidth == null || (itemWidth >= 0 || itemWidth != matchConstraint));
116+ assert (
117+ itemHeight == null || (itemHeight >= 0 || itemHeight != matchConstraint));
103118 assert ((itemSizeBuilder == null && itemWidth != null && itemHeight != null ) ||
104119 (itemSizeBuilder != null && itemWidth == null && itemHeight == null ));
105120 List <Widget > widgets = [];
@@ -151,14 +166,16 @@ List<Widget> constraintGrid({
151166 }
152167 Widget widget = itemBuilder (i);
153168 Size ? itemSize = itemSizeBuilder? .call (i);
169+ double width = itemWidth ?? itemSize! .width;
170+ double height = itemHeight ?? itemSize! .height;
154171 widgets.add (Constrained (
155172 child: widget,
156173 constraint: Constraint (
157174 id: itemId,
158- width: itemWidth ?? itemSize ! . width,
159- height: itemHeight ?? itemSize ! . height,
160- left: leftAnchor,
161- top: topAnchor,
175+ width: width,
176+ height: height,
177+ left: width == matchParent ? null : leftAnchor,
178+ top: height == matchParent ? null : topAnchor,
162179 zIndex: zIndex,
163180 translate: translate,
164181 visibility: visibility,
@@ -1609,6 +1626,9 @@ class _ConstraintRenderBox extends RenderBox
16091626 late bool _debugShowZIndex;
16101627 late bool _debugShowChildDepth;
16111628
1629+ late double _width;
1630+ late double _height;
1631+
16121632 bool _needsRecalculateConstraints = true ;
16131633 bool _needsReorderChildren = true ;
16141634 int _buildNodeTreesCount = 0 ;
@@ -1765,6 +1785,20 @@ class _ConstraintRenderBox extends RenderBox
17651785 }
17661786 }
17671787
1788+ set width (double value) {
1789+ if (_width != value) {
1790+ _width = value;
1791+ markNeedsLayout ();
1792+ }
1793+ }
1794+
1795+ set height (double value) {
1796+ if (_height != value) {
1797+ _height = value;
1798+ markNeedsLayout ();
1799+ }
1800+ }
1801+
17681802 @override
17691803 void setupParentData (covariant RenderObject child) {
17701804 if (child.parentData is ! _ConstraintBoxData ) {
@@ -2102,17 +2136,31 @@ class _ConstraintRenderBox extends RenderBox
21022136 return true ;
21032137 }());
21042138
2105- /// Always fill the parent layout
2106- /// TODO will support wrap_content in the future
2139+ /// TODO will support wrapContent in the future
2140+ double width;
21072141 double consMaxWidth = constraints.maxWidth;
21082142 if (consMaxWidth == double .infinity) {
21092143 consMaxWidth = window.physicalSize.width / window.devicePixelRatio;
21102144 }
2145+ if (_width >= 0 ) {
2146+ width = _width.clamp (constraints.minWidth, consMaxWidth);
2147+ } else {
2148+ width = consMaxWidth;
2149+ }
2150+
2151+ double height;
21112152 double consMaxHeight = constraints.maxHeight;
21122153 if (consMaxHeight == double .infinity) {
21132154 consMaxHeight = window.physicalSize.height / window.devicePixelRatio;
21142155 }
2115- size = constraints.constrain (Size (consMaxWidth, consMaxHeight));
2156+ if (_height >= 0 ) {
2157+ height = _height.clamp (constraints.minHeight, consMaxHeight);
2158+ } else {
2159+ height = consMaxHeight;
2160+ }
2161+
2162+ size = constraints.constrain (Size (width, height));
2163+ assert (constraints.isSatisfiedBy (size));
21162164
21172165 if (_needsRecalculateConstraints) {
21182166 assert (() {
0 commit comments