Padding (Padding)
Padding may be filled to its child nodes is added (blank), and the effect similar margins. It is defined as:
Padding({
...
EdgeInsetsGeometry padding,
Widget child,
})
Attributes:
Attributes | Explanation |
---|---|
padding | padding value, EdgeInsetss set filling value |
child | Subassembly |
EdgeInsetsGeometry is an abstract class development, we generally use EdgeInsets class, which is a subclass of EdgeInsetsGeometry, the definition of a convenient way to fill some of the settings.
EdgeInsets
definition:
class EdgeInsets extends EdgeInsetsGeometry {
// 分别指定四个方向的填充
const EdgeInsets.fromLTRB(this.left, this.top, this.right, this.bottom);
// 所有方向均使用相同数值的填充
const EdgeInsets.all(double value)
: left = value,
top = value,
right = value,
bottom = value;
// 可以设置具体某个方向的填充(可以同时指定多个方向)。
const EdgeInsets.only({
this.left = 0.0,
this.top = 0.0,
this.right = 0.0,
this.bottom = 0.0,
});
// 用于设置对称方向的填充,vertical指top和bottom,horizontal指left和right。
const EdgeInsets.symmetric({
double vertical = 0.0,
double horizontal = 0.0,
}) : left = horizontal,
top = vertical,
right = horizontal,
bottom = vertical;
EdgeInsets convenient way to provide:
- fromLTRB (Double left, Double Top, right Double, Double
bottom): filling four directions are designated. - all (double value): filled with the same value in all directions are used.
- only ({left, top, right, bottom}): a specific direction may be provided to fill (may specify multiple directions simultaneously).
- Symmetric ({Vertical, Horizontal
}): Set for symmetric filling direction, vertical refers to the top and bottom, horizontal refers to the left and right.
Example:
The following example shows the different usage EdgeInsets mainly of:
class PaddingTestRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
//上下左右各添加16像素补白
padding: EdgeInsets.all(16.0),
child: Column(
//显式指定对齐方式为左对齐,排除对齐干扰
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
//左边添加8像素补白
padding: const EdgeInsets.only(left: 8.0),
child: Text("Hello world"),
),
Padding(
//上下各添加8像素补白
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Text("I am Jack"),
),
Padding(
// 分别指定四个方向的补白
padding: const EdgeInsets.fromLTRB(20.0,.0,20.0,20.0),
child: Text("Your friend"),
)
],
),
);
}
}
Run results as shown: