Flutter之EdgeInsets对象(译)

4,236 阅读3分钟

给四个方向设置固定的边距

通常用于给一个盒子的四边设置边距,用这个对象可以设置内边距。

EdgeInsets类根据可视边缘(上、下、左、右)指定边距,这些值不受TextDirection类的影响。要支持从左到右、从右到左布局,请使用EdgeInsetsDirectional类,EdgeInsetsDirectional通过start、end、top和bottom表示,其中start和end通过TextDirection解析。

构造函数:

EdgeInsets.all(double value):四边设置为给定的值

EdgeInsets.fromLTRB(double left, double top, double right, double bottom):四个参数分别设置右边距、上边距、左边距、下边距

EdgeInsets.fromWindowPadding(WindowPadding padding, double devicePixelRatio):按不同屏幕分辨率设置边距,第一个参数是padding值,第二个参数是屏幕分辨率

EdgeInsets.only({double left: 0.0, double top: 0.0, double right: 0.0, double bottom: 0.0 }):给给定方向设置边距,其他方向默认设置为0

EdgeInsets.symmetric({double vertical: 0.0, double horizontal: 0.0 }):设置水平方向或垂直方向边距,即给定一个方向同时设置上下边距或者左右边距,不指定默认为0。

属性:

bottomdouble:下边距,final

topdouble:上边距,final

leftdouble:左边距,final

rightdouble:右边距,final

bottomLeftOffset:从该对象插入的矩形的左下角到该矩形左下角的向量

举个栗子:

const pad =  EdgeInsets.all(10.0);
print(pad.bottomLeft);print(pad.bottomRight);print(pad.topLeft);print(pad.topRight);
结果为:
I/flutter (16700): Offset(10.0, -10.0)
I/flutter (16700): Offset(-10.0, -10.0)
I/flutter (16700): Offset(10.0, 10.0)
I/flutter (16700): Offset(-10.0, 10.0)

bottomRightOffset:从该对象插入的矩形的右下角到该矩形右下角的向量

topLeftOffset:从该对象插入的矩形的左上角到该矩形左上角的向量

topRightOffset:从该对象插入的矩形的右上角到该矩形右上角的向量

flippedEdgeInsets:边距翻转,返回EdgeInsets,但是left,top,right,bottom 的值用原来的right, bottom, left, top值替换了

horizontaldouble:水平方向上边距的总和

verticaldouble:垂直方向上边距的总和

isNonNegativebool:四个边距是否都是非负值

collapsedSizeSizeEdgeInsets占据的空间大小

方法:

add(EdgeInsetsGeometry other) → EdgeInsetsGeometry:返回两个EdgeInsetsGeometry对象叠加之和

copyWith({double left, double top, double right, double bottom }) → EdgeInsets:创建一个EdgeInsets的拷贝,但用新传入的参数作为值

deflateRect(Rect rect) → Rect:返回一个新的矩形,该矩形的每边都比给定的小EdgeInsets设定的值,也就是矩形的左边缘向右移动EdgeInsets设定的left值长度,矩形的右边缘向左移动EdgeInsets设定的right值长度,矩形的上边缘向下移动EdgeInsets设定的top值长度,矩形的下边缘向上移动EdgeInsets设定的bottom值长度

inflateRect(Rect rect) → Rect:返回一个新的矩形,该矩形的每边都比给定的大EdgeInsets设定的值,也就是矩形的左边缘向左移动EdgeInsets设定的left值长度,矩形的右边缘向右移动EdgeInsets设定的right值长度,矩形的上边缘向上移动EdgeInsets设定的top值长度,矩形的下边缘向下移动EdgeInsets设定的bottom值长度

resolve(TextDirection direction) → EdgeInsets:Convert this instance into an EdgeInsets, which uses literal coordinates (i.e. the left coordinate being explicitly a distance from the left, and the right coordinate being explicitly a distance from the right) ~~还没太搞懂

subtract(EdgeInsetsGeometry other) → EdgeInsetsGeometry:返回两个EdgeInsetsGeometry对象之间的差异

along(Axis axis) → double:指定方向(也就是垂直和水平方向)的边距总和

deflateSize(Size size) → Size:返回一个新的尺寸,比原尺寸要小,这个尺寸在原来盒子基础上减去水平和垂方向的边距

inflateSize(Size size) → Size:返回一个新的尺寸,比原尺寸要大,这个尺寸在原来盒子基础上加上水平和垂方向的边距

静态方法:

lerp(EdgeInsets a, EdgeInsets b, double t) → EdgeInsets:在两个EdgeInsets对象之间线性插值


本文是对flutter API进行了翻译,部分删减,转载请写明出处,原文链接,有问题欢迎拍砖