dart – 如何围绕指定的锚点在2D中旋转Container小部件?

前端之家收集整理的这篇文章主要介绍了dart – 如何围绕指定的锚点在2D中旋转Container小部件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想对Container小部件执行一个非常简单的2D旋转(包含一些其他小部件.)此小部件将围绕中心的单个固定点旋转,没有变形.

我尝试使用带有Matrix4.rotationZ的transform属性,这在某种程度上有效 – 但是锚点位于左上角,而不是在中心.是否有一种简单的方法来指定锚点?

此外,是否有更简单的方法来2D旋转这个不需要Matrix4的小部件?

desired and actual transformations

var container = new Container (
  child: new Stack (
    children: [
      new Image.asset ( // background photo
        "assets/texture.jpg",fit: ImageFit.cover,),new Center (
        child: new Container (
          child: new Text (
            "Lorem ipsum",style: new TextStyle(
              color: Colors.white,fontSize: 42.0,fontWeight: FontWeight.w900
            )
          ),decoration: new BoxDecoration (
            backgroundColor: Colors.black,padding: new EdgeInsets.fromLTRB(16.0,16.0,16.0),transform: new Matrix4.rotationZ(0.174533),// rotate -10 deg
        ),],width: 400.0,height: 200.0,);

解决方法

在旋转之前和之后应用平移(往返于支点).

你可以自己创建一个小工具来实现这一点,从而同时解决你的其他问题(隐藏Matrix4).

猜你在找的Flutter相关文章