Unity_UIWidgets学习笔记03_组件_Container

1、源码

public Container(
            Key key = null,//唯一标识符
            Alignment alignment = null,//子元素的排列方式
            EdgeInsets padding = null,//内边距
            Color color = null,//颜色,
            Decoration decoration = null,//绘制在child后面的装饰,设置了decoration的话,就不能设置color属性,否则会报错,此时应该在decoration中进行颜色的设置。
            Decoration forgroundDecoration = null,//绘制在child前面的装饰。
            float? width = null,//container的宽度
            float? height = null,//container的高度
            BoxConstraints constraints = null,//添加到child上额外的约束条件
            EdgeInsets margin = null,//外边距
            Matrix3 transfrom = null,//变换矩阵
            Widget child = null//子元素
        )

2、例子

new Container(
           constraints:BoxConstraints.expand(
            height:Theme.of(context).textTheme.display1.fontSize*1.1f+200f
        ),
           decoration:new BoxDecoration(
               border: Border.all(width: 2.0f, color: Colors.red),
               color: Colors.grey,
               borderRadius: BorderRadius.all(Radius.circular(20.0f)),
               image:new DecorationImage(
                   image:new NetworkImage(@"https://hbimg.huabanimg.com/437658f08a68e1d24ea512b48b4a8cb7d808f3de25148-uBjU7Q_fw658"),
                   centerSlice: Unity.UIWidgets.ui.Rect.fromLTRB(270.0f, 180.0f, 1360.0f, 730.0f)
               )
               

           ),
           alignment:Alignment.center,
           padding:EdgeInsets.all(8),
               margin:EdgeInsets.all(10f),
            //    color:Colors.green,
               child:new Text(
                    "Hello World",
                    style:Theme.of(context)
                                .textTheme
                                .display1
                                .copyWith(color:Colors.black)
        
                 ),
                 transfrom:Matrix3.makeRotate(0.3f)
        );
       

3,简单使用

按钮的状态(正常态、点击态)的颜色变化;

new GestureDetector(
           child:new Container(
                constraints:BoxConstraints.expand(
                    height:Theme.of(context).textTheme.display1.fontSize*1.1f+200f
                ),
                decoration:new BoxDecoration(
                    border: Border.all(width: 2.0f, color: Colors.red),
                    color: btnColor,
                    borderRadius: BorderRadius.all(Radius.circular(80.0f))
                ),
                alignment:Alignment.center,
                padding:EdgeInsets.all(20),
                    margin:EdgeInsets.only(top:350),
                    //    color:Colors.green,
                    child:new Text(
                            "按钮",
                            style:Theme.of(context)
                                        .textTheme
                                        .display1
                                        .copyWith(color:Colors.black)
                
                        )
                 
        ),
        onTapDown:(x)=>
        {
            setState(()=>{
                btnColor=Colors.blue;
            });
        },
        onTapUp:(x)=>{
            setState(()=>{
                btnColor=Colors.grey;
            });
        }
           )
       ;

 

转载于:https://www.cnblogs.com/PandaHome/p/11108439.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值