Flutter之Padding

1 、Padding介绍

Padding用来为子元素添加填充,也就是指定子元素与容器边界的距离,作用基本上与Android中ViewGroup的padding属性差不多

  const Padding({
    Key key,@required this.padding,Widget child,}) : assert(padding != null),super(key: key,child: child);

EdgeInsets提供了一些方法

  • fromLTRB(double left,double top,double right,double bottom):分别指定四个方向的填充。
  • all(double value) : 所有方向均使用相同数值的填充。
  • only({left,top,right,bottom }):可以设置具体某个方向的填充(可以同时指定多个方向)。
  • symmetric({ vertical,horizontal }):用于设置对称方向的填充,vertical指top和bottom,horizontal指left和right。

 

 

 

 

 

 

 

 

 

 

 

 

2 、代码测试

  @override
  Widget build(BuildContext context) {
      return MaterialApp(
          title: 'open url',home: Scaffold(
            appBar: AppBar(
              // Here we take the value from the MyHomePage object that was created by
              // the App.build method,and use it to set our appbar title.
              title: Text('hello flutter'),),body: Padding(
//              padding: EdgeInsets.all(16),//            padding: EdgeInsets.fromLTRB(10,20,30,40),//            padding: EdgeInsets.only(left: 10,right: 30),padding: EdgeInsets.symmetric(vertical: 20),child: Container(
                 color: Colors.blue,);
  }
}

 

 

 

 

 

 

3、运行效果

分别用上面注释的4个padding效果如下

 

相关文章

这篇文章主要讲解了“FlutterComponent动画的显和隐怎么实现...
这篇文章主要讲解了“flutter微信聊天输入框功能如何实现”,...
本篇内容介绍了“Flutter之Navigator的高级用法有哪些”的有...
这篇文章主要介绍“Flutter怎么使用Android原生播放器”,在...
Flutter开发的android端如何修改APP名称,logo,版本号,具体...
Flutter路由管理初识路由概念一.路由管理1.1.Route1.2.Mater...