Flutter Transform变形

Flutter Transform变形

概述

  • Transform可以对子组件进行变化,比如旋转、平移、缩放等。
  • Transform变形是通过矩阵变换实现的,发生在绘制阶段,而不是布局阶段,所以对子组件任何变化,都不会影响其占用的空间。

平移

在这里插入图片描述

DecoratedBox(
    child: Transform.translate(
        offset: Offset(10, 10), //默认原点左上角,向右平移10,向下平移10
        child: Text("hello world"),
    ),
    decoration: BoxDecoration(color: Colors.red),
)

旋转

在这里插入图片描述

DecoratedBox(
    child: Transform.rotate(
        angle: math.pi / 2, //选择90度
        child: Text("hello world"),
    ),
    decoration: BoxDecoration(color: Colors.red),
)

缩放

在这里插入图片描述

DecoratedBox(
    child: Transform.scale(
        scale: 2,
        child: Text("hello world"),
    ),
    decoration: BoxDecoration(color: Colors.red),
)

倾斜

在这里插入图片描述

Container(
    color: Colors.black,
    child: Transform(
        alignment: Alignment.topRight,
        transform: Matrix4.skewY(0.3),
        child: Container(
            padding: EdgeInsets.all(8),
            color: Colors.red,
            child: Text("  hello transform!  "),
        ),
    ),
)

RotatedBox

RotatedBox与Transform.rotate()功能类似,但是RotatedBox是变化是在layout阶段,所以会影响子组件的位置和大小。

在这里插入图片描述

DecoratedBox(
    child: RotatedBox(
        quarterTurns: 1,
        child: Text("hello world"),
    ),
    decoration: BoxDecoration(color: Colors.red),
)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值