Padding(填充)可以给其他子节点填充留白,其结构如下:

flutter-Padding

其padding选项一般使用EdgeInsets类来定义:

flutter-Padding

 

 

 

flutter-Padding

 

 

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: 100.0), //symmetric对称填充,垂直上下各8.0
            child: Text("I am Jack"),
          ),
          Padding(
            // 分别指定四个方向的补白
            padding: const EdgeInsets.fromLTRB(20.0,.0,20.0,20.0),
            child: Text("Your friend"),
          )
        ],
      ),
    );
  }
}

相关文章:

  • 2021-08-11
  • 2022-12-23
  • 2021-04-17
  • 2022-01-13
  • 2021-11-05
  • 2021-12-20
  • 2021-11-29
  • 2021-04-29
猜你喜欢
  • 2021-04-26
  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
  • 2022-12-23
  • 2021-06-16
  • 2022-12-23
相关资源
相似解决方案