invokeLayoutCallback<T extends BoxConstraints> method
- @protected
- void callback(
- T constraints
inherited
Allows mutations to be made to this object's child list during layout.
This is used by LayoutBuilder to build children on-demand during layout. The callback is invoked synchronously, and mutations are only allowed during that callback's execution.
This method ensures that any new render objects created during the callback
are properly merged into the layout pipeline by setting a flag that causes
PipelineOwner.flushLayout to re-sort the dirty nodes list.
Implementation
@protected
void invokeLayoutCallback<T extends BoxConstraints>(
void Function(T constraints) callback,
) {
assert(
_needsLayout == false,
'invokeLayoutCallback must be called during performLayout',
);
// If owner is null (render object not fully attached), just invoke the
// callback directly. This can happen with nested LayoutBuilders where
// an inner LayoutBuilder's render object is created during layout but
// hasn't been fully attached to the tree yet.
if (owner != null) {
owner!._enableMutationsToDirtySubtrees(() {
callback(constraints as T);
});
} else {
callback(constraints as T);
}
}