我想对Container小部件执行一个非常简单的2D旋转(包含一些其他小部件.)此小部件将围绕中心的单个固定点旋转,没有变形.
我尝试使用带有Matrix4.rotationZ的transform属性,这在某种程度上有效 – 但是锚点位于左上角,而不是在中心.是否有一种简单的方法来指定锚点?
此外,是否有更简单的方法来2D旋转这个不需要Matrix4的小部件?
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).