Flutter基础-013-Padding内边距

201 阅读1分钟
属性
const Padding({
    Key key,
    @required this.padding,// 内边距
    Widget child,
  })
  • EdgeInsets.all(12),// 指定四个方向相同的值
  • EdgeInsets.fromLTRB(10, 20, 30, 40),// 分别指定四个方向的值
  • EdgeInsets.only(left: 10,right: 30),// 指定任意方向的值
  • EdgeInsets.symmetric(vertical: 10,horizontal: 50),//指定水平(left right)或垂直方向(top,bottom)的值。

image.png

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: ConstrainedBox(
        constraints: BoxConstraints.expand(),
        child: Padding(
//          padding: EdgeInsets.all(12),// 指定四个方向相同的值
//        padding: EdgeInsets.fromLTRB(10, 20, 30, 40),// 分别指定四个方向的值
//        padding: EdgeInsets.only(left: 10,right: 30),// 指定任意方向的值
        padding: EdgeInsets.symmetric(vertical: 10,horizontal: 50),//指定水平(left right)或垂直方向(top,bottom)的值
          child: Stack(
            fit: StackFit.expand, //
            children: <Widget>[
              Container(
                child: Text(
                  "444",
                  style: TextStyle(backgroundColor: Colors.orange),
                ),
                color: Colors.grey,
              ),
            ],
          ),
        ),
      ),
    );
  }
}