TL;DR
How can I know the layout rules of a widget (what size will it request from its parent and what constraints will it pass to its children) if there is no documentation about it?
The problem details
I have this very basic app
void main() {
runApp(
Container(
color: Colors.red,
width: 20,
height: 20,
),
);
}
I was expecting the Container to have width and height of 20 but I got a Container that filled up the whole screen.
Reading this article on flutter.dev about understanding constraints, in its last part called "Learning the layout rules for specific widgets
", they mention how to do this by finding the createRenderObject method and then finding the performLayout method.
However this createRenderObject method is only available for subclasses of RenderObjectWidget. For example, navigating through code of Transform widget, I find createRenderObject that returns a RenderTransform, that extends RenderProxyBox, which finally implements performLayout as :
@override
void performLayout() {
if (child != null) {
child!.layout(constraints, parentUsesSize: true);
size = child!.size;
} else {
size = computeSizeForNoChild(constraints);
}
}
I can conclude that Transform widget will finally take the size of its child due to this line size = child!.size;.
But in case of Container above, is directly extends StatelessWidget. I couldn't find by navigating through its code the methods performLayout and createRenderObject, I could only find createElement, but I am looking for the RenderObject in the render tree associated with the Container and not the element.
The Question
So the question is how to find this render object associated with a stateless widget/stateful widget in order to know the layout rules that this widget will give to its children and will follow them itself in this case?