@@ -48,9 +48,67 @@ class OffBuildWidget extends StatelessWidget {
4848 int get hashCode => id.hashCode;
4949}
5050
51+ class MultiChildWidgetContext {
52+ static MultiChildWidgetContext ? currentContext;
53+ List <Widget > contextChildren = [];
54+ }
55+
56+ extension MultiChildWidgetChildExt on Widget {
57+ Widget enter () {
58+ MultiChildWidgetContext .currentContext? .contextChildren.add (this );
59+ return this ;
60+ }
61+ }
62+
63+ extension ConstraintLayoutExt on MultiChildRenderObjectWidget {
64+ Widget open (void Function () block) {
65+ MultiChildWidgetContext ? temp = MultiChildWidgetContext .currentContext;
66+ MultiChildWidgetContext context = MultiChildWidgetContext ();
67+ MultiChildWidgetContext .currentContext = context;
68+ block ();
69+ MultiChildWidgetContext .currentContext = temp;
70+ if (this is ConstraintLayout ) {
71+ (this as ConstraintLayout ).children.addAll (context.contextChildren);
72+ } else if (this is Row ) {
73+ Row row = (this as Row );
74+ return Row (
75+ key: key,
76+ mainAxisAlignment: row.mainAxisAlignment,
77+ mainAxisSize: row.mainAxisSize,
78+ crossAxisAlignment: row.crossAxisAlignment,
79+ textDirection: row.textDirection,
80+ verticalDirection: row.verticalDirection,
81+ textBaseline: row.textBaseline,
82+ children: context.contextChildren);
83+ } else if (this is Column ) {
84+ Column column = (this as Column );
85+ return Column (
86+ key: key,
87+ mainAxisAlignment: column.mainAxisAlignment,
88+ mainAxisSize: column.mainAxisSize,
89+ crossAxisAlignment: column.crossAxisAlignment,
90+ textDirection: column.textDirection,
91+ verticalDirection: column.verticalDirection,
92+ textBaseline: column.textBaseline,
93+ children: context.contextChildren);
94+ } else if (this is Stack ) {
95+ Stack stack = (this as Stack );
96+ return Stack (
97+ key: key,
98+ alignment: stack.alignment,
99+ textDirection: stack.textDirection,
100+ fit: stack.fit,
101+ overflow: stack.overflow,
102+ clipBehavior: stack.clipBehavior,
103+ children: context.contextChildren);
104+ }
105+ return this ;
106+ }
107+ }
108+
51109/// For easy use
52- extension ConstrainedWidgetsExt on Widget {
53- Constrained applyConstraint ({
110+ extension ConstrainedWidgetExt on Widget {
111+ Widget applyConstraint ({
54112 ConstraintId ? id,
55113 double width = wrapContent,
56114 double height = wrapContent,
@@ -188,27 +246,27 @@ extension ConstrainedWidgetsExt on Widget {
188246 calcOffsetCallback: calcOffsetCallback,
189247 ),
190248 child: this ,
191- );
249+ ). enter () ;
192250 }
193251
194- Constrained apply ({
252+ Widget apply ({
195253 required Constraint constraint,
196254 }) {
197255 return Constrained (
198256 key: key,
199257 constraint: constraint,
200258 child: this ,
201- );
259+ ). enter () ;
202260 }
203261
204- UnConstrained applyConstraintId ({
262+ Widget applyConstraintId ({
205263 required ConstraintId id,
206264 }) {
207265 return UnConstrained (
208266 key: key,
209267 id: id,
210268 child: this ,
211- );
269+ ). enter () ;
212270 }
213271
214272 /// When the layout is complex, if the child elements need to be repainted frequently, it
0 commit comments