How can I define a baseline for a Stateless widget in Flutter?

Posted by Jennifer | Updated on

If you want to define a baseline you can’t do it directly in the stateless widget. You need to mess around its corresponding RenderBox that needs to implement the computeDistanceToActualBaseline() method.

Give a look to the ListTile implementation here. You will see that the _RenderListTile RenderBox implements the above method returning the baseline of the title widget.

In this case, the baseline of the title is the bottom of the Text widget.

All this is needed because the Baseline widget tries to get the baseline of the child widget. If you don’t provide a explicit baseline with the above method, it just uses its bottom position.

You can find below an example of a BaselineBox where you can set an arbitrary baseline from top.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers