text stringlengths 1 474 |
|---|
Setting container width |
To specify the width of a Container |
widget, use its width property. |
This is a fixed width, unlike the CSS max-width property |
that adjusts the container width up to a maximum value. |
To mimic that effect in Flutter, |
use the constraints property of the Container. |
Create a new BoxConstraints widget with a minWidth or maxWidth.For nested Containers, if the parent’s width is less than the child’s width, |
the child Container sizes itself to match the parent.<topic_end> |
<topic_start> |
Manipulating position and size |
The following examples show how to perform more complex operations |
on widget position, size, and background.<topic_end> |
<topic_start> |
Setting absolute position |
By default, widgets are positioned relative to their parent.To specify an absolute position for a widget as x-y coordinates, |
nest it in a Positioned widget that is, |
in turn, nested in a Stack widget.<topic_end> |
<topic_start> |
Rotating components |
To rotate a widget, nest it in a Transform widget. |
Use the Transform widget’s alignment and origin properties |
to specify the transform origin (fulcrum) in relative and absolute terms, |
respectively.For a simple 2D rotation, in which the widget is rotated on the Z axis, |
create a new Matrix4 identity object |
and use its rotateZ() method to specify the rotation factor |
using radians (degrees × π / 180).<topic_end> |
<topic_start> |
Scaling components |
To scale a widget up or down, nest it in a Transform widget. |
Use the Transform widget’s alignment and origin properties |
to specify the transform origin (fulcrum) in relative or absolute terms, |
respectively.For a simple scaling operation along the x-axis, |
create a new Matrix4 identity object |
and use its scale() method to specify the scaling factor.When you scale a parent widget, |
its child widgets are scaled accordingly.<topic_end> |
<topic_start> |
Applying a linear gradient |
To apply a linear gradient to a widget’s background, |
nest it in a Container widget. |
Then use the Container widget’s decoration property to create a |
BoxDecoration object, and use BoxDecoration’s gradient |
property to transform the background fill.The gradient “angle” is based on the Alignment (x, y) values:<topic_end> |
<topic_start>Vertical gradient |
<topic_end> |
<topic_start>Horizontal gradient |
<topic_end> |
<topic_start> |
Manipulating shapes |
The following examples show how to make and customize shapes.<topic_end> |
<topic_start> |
Rounding corners |
To round the corners of a rectangular shape, |
use the borderRadius property of a BoxDecoration object. |
Create a new BorderRadius |
object that specifies the radius for rounding each corner.<topic_end> |
<topic_start> |
Adding box shadows |
In CSS you can specify shadow offset and blur in shorthand, |
using the box-shadow property. This example shows two box shadows, |
with properties:In Flutter, each property and value is specified separately. |
Use the boxShadow property of BoxDecoration to create a list of |
BoxShadow widgets. You can define one or multiple |
BoxShadow widgets, which can be stacked |
to customize the shadow depth, color, and so on.<topic_end> |
<topic_start> |
Making circles and ellipses |
Making a circle in CSS requires a workaround of applying a |
border-radius of 50% to all four sides of a rectangle, |
though there are basic shapes.While this approach is supported |
with the borderRadius property of BoxDecoration, |
Flutter provides a shape property |
with BoxShape enum for this purpose.<topic_end> |
<topic_start> |
Manipulating text |
The following examples show how to specify fonts and other |
text attributes. They also show how to transform text strings, |
customize spacing, and create excerpts.<topic_end> |
<topic_start> |
Adjusting text spacing |
In CSS, you specify the amount of white space |
between each letter or word by giving a length value |
for the letter-spacing and word-spacing properties, respectively. |
The amount of space can be in px, pt, cm, em, etc.In Flutter, you specify white space as logical pixels |
(negative values are allowed) |
for the letterSpacing and wordSpacing properties |
of a TextStyle child of a Text widget.<topic_end> |
<topic_start> |
Making inline formatting changes |
A Text widget lets you display text |
with some formatting characteristics. |
To display text that uses multiple styles |
(in this example, a single word with emphasis), |
use a RichText widget instead. |
Its text property can specify one or more |
TextSpan objects that can be individually styled.In the following example, “Lorem” is in a TextSpan |
with the default (inherited) text styling, |
and “ipsum” is in a separate TextSpan with custom styling.<topic_end> |
<topic_start> |
Creating text excerpts |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.