The size of this render box computed during layout.
This value is stale whenever this object is marked as needing layout. During performLayout, do not read the size of a child unless you pass true for parentUsesSize when calling the child's layout function.
The size of a box should be set only during the box's performLayout or performResize functions. If you wish to change the size of a box outside of those functins, call markNeedsLayout instead to schedule a layout of the box.
Source
Size get size {
assert(hasSize);
assert(() {
if (_size is _DebugSize) {
final _DebugSize _size = this._size;
assert(_size._owner == this);
if (RenderObject.debugActiveLayout != null) {
// We are always allowed to access our own size (for print debugging
// and asserts if nothing else). Other than us, the only object that's
// allowed to read our size is our parent, if they've said they will.
// If you hit this assert trying to access a child's size, pass
// "parentUsesSize: true" to that child's layout().
assert(debugDoingThisResize || debugDoingThisLayout ||
(RenderObject.debugActiveLayout == parent && _size._canBeUsedByParent));
}
assert(_size == this._size);
}
return true;
});
return _size;
}
Source
@protected
set size(Size value) {
assert(!(debugDoingThisResize && debugDoingThisLayout));
assert(sizedByParent || !debugDoingThisResize);
assert(() {
if ((sizedByParent && debugDoingThisResize) ||
(!sizedByParent && debugDoingThisLayout))
return true;
assert(!debugDoingThisResize);
String contract, violation, hint;
if (debugDoingThisLayout) {
assert(sizedByParent);
violation = 'It appears that the size setter was called from performLayout().';
hint = '';
} else {
violation = 'The size setter was called from outside layout (neither performResize() nor performLayout() were being run for this object).';
if (owner != null && owner.debugDoingLayout)
hint = 'Only the object itself can set its size. It is a contract violation for other objects to set it.';
}
if (sizedByParent)
contract = 'Because this RenderBox has sizedByParent set to true, it must set its size in performResize().';
else
contract = 'Because this RenderBox has sizedByParent set to false, it must set its size in performLayout().';
throw new FlutterError(
'RenderBox size setter called incorrectly.\n'
'$violation\n'
'$hint\n'
'$contract\n'
'The RenderBox in question is:\n'
' $this'
);
});
assert(() {
if (value is _DebugSize) {
if (value._owner != this) {
assert(value._owner.parent == this);
assert(value._canBeUsedByParent);
}
}
return true;
});
_size = value;
assert(() {
_size = new _DebugSize(_size, this, debugCanParentUseSize);
return true;
});
assert(() { debugAssertDoesMeetConstraints(); return true; });
}