1. Flutter EdgeInsets
EdgeInsets用于根据视觉参数左、上、右和下为 Widget 创建外部填充或内部填充,它不依赖于文本方向。
要同时支持从左到右和从右到左的布局,应该考虑使用 EdgeInsetsDirectional 。
EdgeInsets.all构造函数
EdgeInsets.all构造函数用于为所有四个 left、top、right、bottom 属性创建一个具有相同值的 EdgeInsets 对象。
const EdgeInsets.all(
double value
)
示例代码 -
Container (
margin: EdgeInsets.all(80),
color: Colors.greenAccent,
child:Text(
"Hi There!",
style: TextStyle(fontSize: 28)
)
)
3. EdgeInsets.fromLTRB
EdgeInsets.fromLTRB 构造函数用于根据 left、top、right 和 bottom 值创建 EdgeInsets 对象。
const EdgeInsets.fromLTRB(
double left,
double top,
double right,
double bottom
)
示例代码:
Padding (
padding: EdgeInsets.fromLTRB(80, 100, 70, 50),
child: ElevatedButton (
child: Text("Button"),
onPressed: (){}
)
)
示例显示效果如下 -
EdgeInsets.fromWindowPadding属性
const EdgeInsets.fromWindowPadding(
WindowPadding padding,
double devicePixelRatio
)