text stringlengths 1 372 |
|---|
their single child at 0,0 relative to their own origin, which |
requires no computation or storage at all. some render objects |
avoid computing the position of their children until the last |
possible moment (for example, during the paint phase), to avoid |
the computation entirely if they are not subsequently painted. |
4 there exists one exception to this rule. |
as discussed in the building widgets on demand |
section, some widgets can be rebuilt as a result of a change in layout |
constraints. if a widget marked itself dirty for unrelated reasons in |
the same frame that it also is affected by a change in layout constraints, |
it will be updated twice. this redundant build is limited to the |
widget itself and does not impact its descendants. |
5 a key is an opaque object optionally |
associated with a widget whose equality operator is used to influence |
the reconciliation algorithm. |
6 for accessibility, and to give applications |
a few extra milliseconds between when a widget is built and when it |
appears on the screen, the viewport creates (but does not paint) |
widgets for a few hundred pixels before and after the visible widgets. |
7 this approach was first made popular by |
facebook’s react library. |
8 in practice, the t value is allowed |
to extend past the 0.0-1.0 range, and does so for some curves. for |
example, the “elastic” curves overshoot briefly in order to represent |
a bouncing effect. the interpolation logic typically can extrapolate |
past the start or end as appropriate. for some types, for example, |
when interpolating colors, the t value is effectively clamped to |
the 0.0-1.0 range. |
<topic_end> |
<topic_start> |
understanding constraints |
info note |
if you are experiencing specific layout errors, |
you might check out common flutter errors. |
when someone learning flutter asks you why some widget |
with width: 100 isn’t 100 pixels wide, |
the default answer is to tell them to put that widget |
inside of a center, right? |
don’t do that. |
if you do, they’ll come back again and again, |
asking why some FittedBox isn’t working, |
why that column is overflowing, or what |
IntrinsicWidth is supposed to be doing. |
instead, first tell them that flutter layout is very different |
from HTML layout (which is probably where they’re coming from), |
and then make them memorize the following rule: |
flutter layout can’t really be understood without knowing |
this rule, so flutter developers should learn it early on. |
in more detail: |
for example, if a composed widget contains a column |
with some padding, and wants to lay out its two children |
as follows: |
the negotiation goes something like this: |
widget: “hey parent, what are my constraints?” |
parent: “you must be from 0 to 300 pixels wide, |
and 0 to 85 tall.” |
widget: “hmmm, since i want to have 5 pixels of padding, |
then my children can have at most 290 pixels of width |
and 75 pixels of height.” |
widget: “hey first child, you must be from 0 to 290 |
pixels wide, and 0 to 75 tall.” |
first child: “ok, then i wish to be 290 pixels wide, |
and 20 pixels tall.” |
widget: “hmmm, since i want to put my second child below the |
first one, this leaves only 55 pixels of height for |
my second child.” |
widget: “hey second child, you must be from 0 to 290 wide, |
and 0 to 55 tall.” |
second child: “ok, i wish to be 140 pixels wide, |
and 30 pixels tall.” |
widget: “very well. my first child has position x: 5 and y: 5, |
and my second child has x: 80 and y: 25.” |
widget: “hey parent, i’ve decided that my size is going to be 300 |
pixels wide, and 60 pixels tall.” |
<topic_end> |
<topic_start> |
limitations |
flutter’s layout engine is designed to be a one-pass process. |
this means that flutter lays out its widgets very efficiently, |
but does result in a few limitations: |
a widget can decide its own size only within the |
constraints given to it by its parent. |
this means a widget usually |
can’t have any size it wants. |
a widget can’t know and doesn’t decide its own position |
in the screen, since it’s the widget’s parent who decides |
the position of the widget. |
since the parent’s size and position, in its turn, |
also depends on its own parent, it’s impossible to |
precisely define the size and position of any widget |
without taking into consideration the tree as a whole. |
if a child wants a different size from its parent and |
the parent doesn’t have enough information to align it, |
then the child’s size might be ignored. |
be specific when defining alignment. |
in flutter, widgets are rendered by their underlying |
RenderBox objects. many boxes in flutter, |
especially those that just take a single child, |
pass their constraint on to their children. |
generally, there are three kinds of boxes, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.