简体   繁体   English

使用 Flutter 框架的 Container 小部件中的边距和填充有什么区别?

[英]what the difference between margin and padding in Container widget using Flutter framework?




class app1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return (MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Hello ',
        home: Material(
          child: Container (
            alignment: Alignment.topCenter ,
            //padding: EdgeInsets.all (30 ),
            margin: EdgeInsets.all(30),
            child: Row(
              children: <Widget> [
                Text ( 'Hello There ' , style: TextStyle (fontSize: 30 ) ),
                ],
              ),
          ),
          ),



          )
    );

  }
}

I have a text widget when i apply the margin and after that apply the padding same result?当我应用边距时我有一个文本小部件,然后应用填充相同的结果? so what's the different?那么有什么不同呢? 在此处输入图像描述

Padding: is the inner space of the element to the edge Padding:是元素到边缘的内部空间

Margin: is the space between widgets together边距:是小部件之间的间距

在此处输入图像描述

在此处输入图像描述

Easy Method:简易方法:

**Padding is Space Around means in the container. **Padding 是 Space Around 的意思是在容器中。

Margin is Space outside means out side of the container** Margin is Space outside 是指容器外侧**

Margin is the space around the widget.边距是小部件周围的空间。 For example, from the edge of the container to the edge of the phone screen.例如,从容器边缘到手机屏幕边缘。

Padding is the space within the widget.填充是小部件内的空间。 For example, from the edge of the container to the text in it.例如,从容器的边缘到其中的文本。

Check out this video from the flutter team around 0:40 to see a quick visual.在 0:40 左右观看 flutter 团队的视频,快速了解一下。https://api.flutter.dev/flutter/widgets/Container-class.htmlhttps://api.flutter.dev/flutter/widgets/Container-class.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM