简体   繁体   English

Flutter padding、margin 和 alginment 最佳实践

[英]Flutter padding, margin and alginment best practices

What is the best practice in flutter for padding,margin etc.填充,边距等的颤振的最佳实践是什么?

example:例子:

I made a simple drawer in flutter.我在颤动中做了一个简单的抽屉。 To make everything to position in places I want.使一切都定位在我想要的位置。 I used padding extensively.我广泛使用了填充。

Now the issue is when I test it on different phone of different size.现在的问题是当我在不同尺寸的不同手机上测试它时。 the positions are inconsistent across different devices.不同设备的位置不一致。

From the Flutter Docs :来自颤振文档

Design discussion Why use a Padding widget rather than a Container with a Container.padding property?设计讨论 为什么使用 Padding 小部件而不是具有 Container.padding 属性的 Container? There isn't really any difference between the two.两者其实没什么区别。 If you supply a Container.padding argument, Container simply builds a Padding widget for you.如果您提供 Container.padding 参数,Container 只需为您构建一个 Padding 小部件。

Container doesn't implement its properties directly. Container 不直接实现其属性。 Instead, Container combines a number of simpler widgets together into a convenient package.相反,Container 将许多更简单的小部件组合到一个方便的包中。 For example, the Container.padding property causes the container to build a Padding widget and the Container.decoration property causes the container to build a DecoratedBox widget.例如,Container.padding 属性使容器构建 Padding 小部件,Container.decoration 属性使容器构建 DecoratedBox 小部件。 If you find Container convenient, feel free to use it.如果您觉得 Container 方便,请随意使用它。 If not, feel free to build these simpler widgets in whatever combination meets your needs.如果没有,请随意以任何满足您需求的组合来构建这些更简单的小部件。

In fact, the majority of widgets in Flutter are simply combinations of other simpler widgets.事实上,Flutter 中的大多数小部件只是其他更简单的小部件的简单组合。 Composition, rather than inheritance, is the primary mechanism for building up widgets.组合而不是继承是构建小部件的主要机制。

So, no worries about padding widgets.所以,不用担心填充小部件。 A good practice to get some spaces inside a Column() or Row() is using SizedBox() .Column()Row()获得一些空间的一个好做法是使用SizedBox() Then you add an extra space setting up width or height.然后添加一个额外的空间来设置宽度或高度。

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

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