Guide
Widget Gallery
This page describes the widgets available in Sky. These widgets are
general-purpose and don’t offer an opinion about the visual style of your app.
Container
Container is a general-purpose widget that combines several basic widgets in
order to make them easier to use.
BoxDecoration decorationDraw the given decoration around this container.double widthForces the container to have the given width.double heightForce the container to have the given height.EdgeDims marginSurrounds the container (i.e., outside the container’s
decoration) on the top, right, bottom, and left with the given amount of
space.EdgeDims paddingSurrounds the container’s child (i.e., inside the
container’s decoration) on the top, right, bottom, and left with the given
amount of space.Matrix4 transformApply the given matrix before painting the container.BoxConstraints constraintsForce the width and height of the container to
respect the given constraints.
Layout models
There are two flex layout models:
Row: Layout a list of child widgets in the horizontal direction.Column: Layout a list of child widgets in the vertical direction.
The direction along which the widgets are laid out is called the
main direction and the other axis is called the cross direction.
These flex widgets size themselves to the maximum size permitted by
its parent, unless that would be infinite size, in which case they
shrink-wrap their children. For details, see flex.md.
Each child of a flex widget is either flexible or inflexible.
The flex first lays out its inflexible children and subtracts their
total length along the main direction to determine how much free space
is available. The flex then divides this free space among the flexible
children in a ratio determined by their flex properties.
The alignItems property determines how children are positioned in
the cross direction. The justifyContent property determines how the
remaining free space (if any) in the main direction is allocated.
Flexible: Mark this child as being flexible with the givenflexratio.
There is also a stacking layout model:
Stack: Layout a list of child widgets on top of each other from back to
front. Each child of aStackwidget is either positioned or
non-positioned. The stack sizes itself to the contain all the
non-positioned children, which are located at the top-left corner of the
stack. The positioned children are then located relative to the stack
according to theirtop,right,bottom, andleftproperties.Positioned: Mark this child as positioned. If thetopproperty is
non-null, the top edge of this child will be positionedtoplayout units
from the top of the stack widget. Theright,bottom, andright
properties work analogously. Note that if the both thetopandbottom
properties are non-null, then the child will be forced to have exactly the
height required to satisfy both constraints. Similarly, setting therightandleftproperties to non-null values will force the child to
have a particular width.
Positioning and sizing
PaddingSurround the child with empty space on the top, right, bottom, and
left according to the givenEdgeDims.CenterCenter the child widget within the space occupied by this widget.SizedBoxForce the child widget to have a particularwidthorheight
(or both).ConstrainedBoxApply the givenBoxConstraintsto the child widget as
additional constraints during layout. This widget is a generalization ofSizedBox.AspectRatioForce the child widget’s width and height to have the givenaspectRatio, expressed as a ratio of width to height.TransformApply the given matrix to the child before painting the child.
This widget is useful for adjusting the visual size and position of a widget
without affecting layout.ViewportLayout the child widget at a larger size than fits in this widget
and render only the portion of the child that is visually contained by this
widget. When rendering, addoffsetto the child’s vertical position to
control which part of the child is visible through the viewport.
TODO(abarth): Add support for horizontal viewporting.SizeObserverWhenever the child widget changes size, this widget calls thecallback. Warning: If the callback changes state that affects the size of
the child widget, it is possible to create an infinite loop.ShrinkWrapWidthForce the child widget to have a width equal to its max
intrinsic width. TODO(abarth): Add a link to the definition of max intrinsic
width. Optionally, round up the child widget’s width or height (or both) to
a multiple ofstepWidthorstepHeight, respectively. Note: The layout
performed byShrinkWrapWidthis relatively expensive and should be used
sparingly.BaselineIf the child widget has aTextBaselineof the givenbaselineType, position the child such that its baseline is atbaseline
layout units from the top of this widget.
Painting effects
OpacityAdjusts the opacity of the child widget, making the child partially
transparent. The amount of transparency is controlled byopacity, with 0.0
0.0 is fully transparent and 1.0 is fully opaque.ClipRectApply a rectangular clip to the child widget. The dimensions of
the clip match the dimensions of the child.ClipRRectApply a rounded-rect clip the child widget. The bounds of the
clip match the bounds of the child widget withxRadiusandyRadius
controlling the x and y radius of the rounded corner, respectively.ClipOvalApply an oval clip to the child widget. The oval will be
axis-aligned, with its horizontal and vertical bounds matching the bounds of
the child widget.DecoratedBoxDraw the givenBoxDecorationsurrounding the child widget.ColorFilterApplies a color filter to the child widget, for example to
tint the child a given color.CustomPaintCallscallbackduring the paint phase with the currentCanvasandSize. The widget occupies the region of the canvas starting at
the origin (i.e.,x = 0.0andy = 0.0) and of the given size (i.e.,x = size.widthandy = size.height).Use the
tokento invalidate the painting. As long as the any newtoken
isoperator==the currenttoken, theCustomPaintwidget is permitted
to retain a recording of the painting produced by the previouscallback
call.