@@ -48,9 +48,67 @@ class OffBuildWidget extends StatelessWidget {
48
48
int get hashCode => id.hashCode;
49
49
}
50
50
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
+
51
109
/// For easy use
52
- extension ConstrainedWidgetsExt on Widget {
53
- Constrained applyConstraint ({
110
+ extension ConstrainedWidgetExt on Widget {
111
+ Widget applyConstraint ({
54
112
ConstraintId ? id,
55
113
double width = wrapContent,
56
114
double height = wrapContent,
@@ -188,27 +246,27 @@ extension ConstrainedWidgetsExt on Widget {
188
246
calcOffsetCallback: calcOffsetCallback,
189
247
),
190
248
child: this ,
191
- );
249
+ ). enter () ;
192
250
}
193
251
194
- Constrained apply ({
252
+ Widget apply ({
195
253
required Constraint constraint,
196
254
}) {
197
255
return Constrained (
198
256
key: key,
199
257
constraint: constraint,
200
258
child: this ,
201
- );
259
+ ). enter () ;
202
260
}
203
261
204
- UnConstrained applyConstraintId ({
262
+ Widget applyConstraintId ({
205
263
required ConstraintId id,
206
264
}) {
207
265
return UnConstrained (
208
266
key: key,
209
267
id: id,
210
268
child: this ,
211
- );
269
+ ). enter () ;
212
270
}
213
271
214
272
/// When the layout is complex, if the child elements need to be repainted frequently, it
0 commit comments