@@ -51,6 +51,8 @@ import 'package:flutter/rendering.dart';
5151/// 5. constraint integrity hint
5252/// 6. bias
5353/// 7. z-index
54+ /// 8. percentage layout
55+ /// 9. guideline
5456///
5557/// not implement
5658/// . guideline
@@ -135,6 +137,7 @@ List<Constrained> hChain({
135137}) {
136138 assert (hChainList.length > 1 ,
137139 'The number of child elements in the chain must be > 1.' );
140+ for (final constrained in hChainList) {}
138141 return [];
139142}
140143
@@ -232,6 +235,8 @@ class _ConstraintBoxData extends ContainerBoxParentData<RenderBox> {
232235 String ? baselineToBottom;
233236 String ? baselineToBaseline;
234237 TextBaseline ? textBaseline;
238+ double ? widthPercent;
239+ double ? heightPercent;
235240}
236241
237242class Constrained extends ParentDataWidget <_ConstraintBoxData > {
@@ -283,6 +288,12 @@ class Constrained extends ParentDataWidget<_ConstraintBoxData> {
283288 final Offset translate;
284289 final bool translateConstraint;
285290
291+ // only takes effect when width is CL.matchConstraint
292+ final double widthPercent;
293+
294+ // only takes effect when height is CL.matchConstraint
295+ final double heightPercent;
296+
286297 // TODO support chain
287298 // final ChainStyle? chainStyle;
288299 // TODO support circle positioned
@@ -322,7 +333,15 @@ class Constrained extends ParentDataWidget<_ConstraintBoxData> {
322333 this .baselineToBottom,
323334 this .baselineToBaseline,
324335 this .textBaseline = TextBaseline .alphabetic,
325- }) : super (
336+ this .widthPercent = 1 ,
337+ this .heightPercent = 1 ,
338+ }) : assert (child is ! Constrained ,
339+ 'Constrained can not be wrapped with Constrained.' ),
340+ assert (child is ! Guideline ,
341+ 'Guideline can not be wrapped with Constrained.' ),
342+ assert (
343+ child is ! Barrier , 'Barrier can not be wrapped with Constrained.' ),
344+ super (
326345 key: key,
327346 child: child,
328347 );
@@ -343,9 +362,6 @@ class Constrained extends ParentDataWidget<_ConstraintBoxData> {
343362
344363 @override
345364 void applyParentData (RenderObject renderObject) {
346- assert (renderObject is ! _InternalBox ,
347- 'Guideline, Barrier can not be wrapped with Constrained.' );
348-
349365 // bounds check
350366 assert (checkSize (width));
351367 assert (checkSize (height));
@@ -365,6 +381,8 @@ class Constrained extends ParentDataWidget<_ConstraintBoxData> {
365381 'baselineToBaseline' , this .baselineToBaseline));
366382 assert (_debugEnsurePercent ('horizontalBias' , horizontalBias));
367383 assert (_debugEnsurePercent ('verticalBias' , verticalBias));
384+ assert (_debugEnsurePercent ('widthPercent' , widthPercent));
385+ assert (_debugEnsurePercent ('heightPercent' , heightPercent));
368386
369387 String ? leftToLeft = this .leftToLeft;
370388 String ? leftToRight = this .leftToRight;
@@ -641,6 +659,16 @@ class Constrained extends ParentDataWidget<_ConstraintBoxData> {
641659 }
642660 }
643661
662+ if (parentData.widthPercent != widthPercent) {
663+ parentData.widthPercent = widthPercent;
664+ needsLayout = true ;
665+ }
666+
667+ if (parentData.heightPercent != heightPercent) {
668+ parentData.heightPercent = heightPercent;
669+ needsLayout = true ;
670+ }
671+
644672 if (needsLayout) {
645673 AbstractNode ? targetParent = renderObject.parent;
646674 if (targetParent is RenderObject ) {
@@ -1232,7 +1260,7 @@ class _ConstraintRenderBox extends RenderBox
12321260 } else {
12331261 right -= _getRightInsets (margin);
12341262 }
1235- minWidth = right - left;
1263+ minWidth = ( right - left) * element.widthPercent ;
12361264 assert (() {
12371265 if (_debugCheckConstraints) {
12381266 if (minWidth < 0 ) {
@@ -1287,7 +1315,7 @@ class _ConstraintRenderBox extends RenderBox
12871315 } else {
12881316 bottom -= _getBottomInsets (margin);
12891317 }
1290- minHeight = bottom - top;
1318+ minHeight = ( bottom - top) * element.heightPercent ;
12911319 assert (() {
12921320 if (_debugCheckConstraints) {
12931321 if (minHeight < 0 ) {
@@ -1677,6 +1705,10 @@ class _ConstrainedNode {
16771705
16781706 TextBaseline get textBaseline => parentData.textBaseline! ;
16791707
1708+ double get widthPercent => parentData.widthPercent! ;
1709+
1710+ double get heightPercent => parentData.heightPercent! ;
1711+
16801712 set offset (Offset value) {
16811713 parentData.offset = value;
16821714 }
0 commit comments