@@ -169,6 +169,7 @@ extension WidgetsExt on Widget {
169
169
@_wrapperConstraint ConstraintId ? bottomRightTo,
170
170
@_wrapperConstraint ConstraintId ? centerHorizontalTo,
171
171
@_wrapperConstraint ConstraintId ? centerVerticalTo,
172
+ OnLayoutCallback ? callback,
172
173
}) {
173
174
return Constrained (
174
175
key: key,
@@ -206,6 +207,7 @@ extension WidgetsExt on Widget {
206
207
bottomRightTo: bottomRightTo,
207
208
centerHorizontalTo: centerHorizontalTo,
208
209
centerVerticalTo: centerVerticalTo,
210
+ callback: callback,
209
211
),
210
212
child: this ,
211
213
);
@@ -352,6 +354,8 @@ class _Align {
352
354
int get hashCode => id.hashCode ^ type.hashCode;
353
355
}
354
356
357
+ typedef OnLayoutCallback = void Function (RenderObject renderObject, Rect rect);
358
+
355
359
class Constraint {
356
360
/// id can be null, but not an empty string
357
361
final ConstraintId ? id;
@@ -433,6 +437,8 @@ class Constraint {
433
437
@_wrapperConstraint
434
438
final ConstraintId ? centerVerticalTo;
435
439
440
+ final OnLayoutCallback ? callback;
441
+
436
442
const Constraint ({
437
443
this .id,
438
444
required this .width,
@@ -467,6 +473,7 @@ class Constraint {
467
473
@_wrapperConstraint this .bottomRightTo,
468
474
@_wrapperConstraint this .centerHorizontalTo,
469
475
@_wrapperConstraint this .centerVerticalTo,
476
+ this .callback,
470
477
});
471
478
472
479
@override
@@ -506,7 +513,8 @@ class Constraint {
506
513
bottomCenterTo == other.bottomCenterTo &&
507
514
bottomRightTo == other.bottomRightTo &&
508
515
centerHorizontalTo == other.centerHorizontalTo &&
509
- centerVerticalTo == other.centerVerticalTo;
516
+ centerVerticalTo == other.centerVerticalTo &&
517
+ callback == other.callback;
510
518
511
519
@override
512
520
int get hashCode =>
@@ -542,7 +550,8 @@ class Constraint {
542
550
bottomCenterTo.hashCode ^
543
551
bottomRightTo.hashCode ^
544
552
centerHorizontalTo.hashCode ^
545
- centerVerticalTo.hashCode;
553
+ centerVerticalTo.hashCode ^
554
+ callback.hashCode;
546
555
547
556
bool checkSize (double size) {
548
557
if (size == matchParent || size == wrapContent || size == matchConstraint) {
@@ -798,6 +807,8 @@ class Constraint {
798
807
needsLayout = true ;
799
808
}
800
809
810
+ parentData.callback = callback;
811
+
801
812
if (needsLayout) {
802
813
AbstractNode ? targetParent = renderObject.parent;
803
814
if (targetParent is RenderObject ) {
@@ -851,6 +862,7 @@ class _ConstraintBoxData extends ContainerBoxParentData<RenderBox> {
851
862
PercentageAnchor ? heightPercentageAnchor;
852
863
double ? horizontalBias;
853
864
double ? verticalBias;
865
+ OnLayoutCallback ? callback;
854
866
}
855
867
856
868
class Constrained extends ParentDataWidget <_ConstraintBoxData > {
@@ -1625,6 +1637,12 @@ class _ConstraintRenderBox extends RenderBox
1625
1637
}
1626
1638
1627
1639
element.offset = Offset (offsetX, offsetY);
1640
+ if (element.callback != null ) {
1641
+ element.callback! .call (
1642
+ element.renderBox! ,
1643
+ Rect .fromLTWH (offsetX, offsetY, element.getMeasuredWidth (size),
1644
+ element.getMeasuredHeight (size)));
1645
+ }
1628
1646
}
1629
1647
}
1630
1648
@@ -1847,6 +1865,8 @@ class _ConstrainedNode {
1847
1865
PercentageAnchor get heightPercentageAnchor =>
1848
1866
parentData.heightPercentageAnchor! ;
1849
1867
1868
+ OnLayoutCallback ? get callback => parentData.callback;
1869
+
1850
1870
set offset (Offset value) {
1851
1871
parentData.offset = value;
1852
1872
}
0 commit comments