FlutterFlutter

Flutter组件Container的属性讲解

2022-07-05  本文已影响0人  漆先生

一、使用场景

  1. 设置宽高:flutter中大部分组件不能设置宽高,需要依赖容器。
  2. 添加背景颜色
  3. 添加背影图像
  4. 添加内外边距:padding和margin
  5. 添加边框
  6. 设置圆角
  7. 设置child对齐:居中、居左、居右、居上、居下或偏移
  8. 设置变换:旋转或变形

二、Container的大小

  1. 如果设置的宽高不在constraints范围内,设置的宽高会无效;
  2. 如果它有child,它会尽可能小。如果不设置宽高和约束,相当于child的大小。如果设置了宽高和约束,以设置最小有效值为准;
  3. 如果它没有child,它会尽可能大。如果不设置宽度和约束,相当于parent的大小。如果设置了宽高和约束,以设置的最大有效值为准。

三、属性

  Container({
    Key? key,
    this.alignment,
    this.padding,
    this.color,
    this.decoration,
    this.foregroundDecoration,
    double? width,
    double? height,
    BoxConstraints? constraints,
    this.margin,
    this.transform,
    this.transformAlignment,
    this.child,
    this.clipBehavior = Clip.none,
  })

alignmentchild对齐的属性,可以设置居中、居左、居右、居上、居下。Alignment(0,0)代表居中,Alignment(-1,-1)表示左上,Alignment(0,-1)表示中上,Alignment(1,-1)表示右上,Alignment(1,1)表示右下
padding内边距
color北京颜色
decoration装饰,边框、圆角、背景图片等
foregroundDecoration前景装饰,绘制在孩子前面
width
height
constraints约束,minWidth、minHeight、maxWidth、maxHeight。
margin外边距
transform变换,如翻转,旋转,变形等
transformAlignment变换时,对于容器大小的对齐
child子组件
clipBehavior剪辑原则,默认是Clip.none

上一篇下一篇

猜你喜欢

热点阅读