Flutter Container 组件

目录

参数详解

代码示例

效果图

完整代码


Container 官网简介:一个便利的小部件,结合了常见的绘画,定位和大小调整小部件。

其实就是一个容器组件,既然是容器,那么,就一定可以装很多东西,而Container装的东西就是Flutter 其他组件。

参数详解

属性说明
alignmenttopCenter:顶部居中对齐
topLeft:顶部左对齐
topRight:顶部右对齐
center:水平垂直居中对齐
centerLeft:垂直居中水平居左对齐
centerRight:垂直居中水平居右对齐
bottomCenter 底部居中对齐
bottomLeft:底部居左对齐
bottomRight:底部居右对齐
padding

内边距

margin外边距
color背景色
decoration装饰  BoxDecoration类型
foregroundDecoration前景装饰
width容器宽
height容器高
constraints应用于子元素的附加约束
transform

Container 容器进行一些旋转、移动之类的操作

child容器子元素

在这里对decoration属性进行详解,先看代码:

Container(
 decoration: BoxDecoration(
  //背景涂颜色
  color: Colors.yellow,
  border: Border.all(
   //边框颜色
   color: Colors.blue,
   //边框宽
   width: 2.0,
  ),
  borderRadius: BorderRadius.all(
   //圆角角度
   Radius.circular(10)
  )
 ),
),

以上介绍了decoration的简单使用,以下介绍以下BoxDecoration的属性:

属性说明
color颜色
image图片
border边框
borderRadius边框圆角度
boxShadow阴影  可以多色混合
gradient渐变
backgroundBlendMode背景
shape

容器形状,BoxShape.rectangle  矩形;BoxShape.circle 圆形

以上属性遵循原则:

1、gradient  >  image >  color    就是说 他们同时使用时 会优先显示gradient定义内容

2、shape不能同borderRadius一起使用  冲突,编译错误

 

代码示例

Center(
          child: Container(
            child: Text(
              '位于右侧的文本',
              textAlign: TextAlign.right,
              style: TextStyle(backgroundColor: Colors.blueAccent),//文字背景
            ),
            //容器高
            height: 300.0,
            //容器宽
            width: 300.0,
            //内边距
            padding: EdgeInsets.all(10),
            //装饰
            decoration: BoxDecoration(
              //颜色
              color: Colors.yellow,
              //边框
              border: Border.all(
                // 边框颜色
                color: Colors.blue,
                //边框宽度
                width: 2.0,
              ),
              //边框圆角度 
              borderRadius: BorderRadius.all(
                Radius.circular(10)
              ),
              //容器形状 默认矩形
              // shape: BoxShape.circle
              //阴影   可以多色混合
              boxShadow:[
                    BoxShadow(
                      color: Colors.green,
                      blurRadius: 50.0,
                    ),
                    BoxShadow(
                      color: Colors.red,
                      blurRadius: 50.0,
                    ),
              ],
              //背景渐变 可以多色渐变
              gradient: LinearGradient(colors: [Colors.red,Colors.blue]),
            ),
            
          ),
    );

效果图

请注意   混合颜色  和  渐变颜色 的区别

完整代码

查看完整代码

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

马志武

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值