dart - 如何围绕指定的 anchor 旋转 2D 容器小部件?

标签 dart flutter

I'd like to perform a very simple 2D rotation of a Container widget (that contains a handful of other widgets.) This widget would be rotated around a single fixed point in the center, with no deformations.

I tried using the transform property with Matrix4.rotationZ, which somewhat works – but the anchor point is in the top-left corner, not in the center. Is there an easy way to specify that anchor point?

Furthermore, is there an easier way to 2D-rotate this widget that doesn't require 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, 16.0),
          transform: new Matrix4.rotationZ(0.174533), // rotate -10 deg
        ),
      ),
    ],
  ),
  width: 400.0,
  height: 200.0,
);

最佳答案

您可以使用 RotatedBox Widget 来旋转任何小部件:

RotatedBox(
    quarterTurns: 3,
    child: Container(
        color:Colors.red
    ),
),

关于dart - 如何围绕指定的 anchor 旋转 2D 容器小部件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41603111/

相关文章:

dart - 核心样式和类似乎不起作用

dart - 附加 ScrollController 时的事件

flutter - 在有状态小部件外部调用方法以使用 flutter Bloc 更新 UI

flutter - 如何在flutter redux中更新列表的属性

android - Flutter:任务 ':app:compileDebugKotlin' 执行失败

flutter - 除非我打印它,否则不在 .map() 中执行 setState

flutter - 如何解决flutter中的OS错误: Permission denied, errno = 13

android - Flutter Android - Gradle 任务 bundleRelease 失败,退出代码为 1

多次调用 Flutter 构建

java - 在 Flutter 中从 Play 商店获取产品时应用内购买崩溃