繁体   English   中英

我如何在 flutter 中旋转我的小盒子?

[英]How do i rotate my fractionally sized box in flutter?

我是 flutter 的新手,我正在尝试将我的盒子旋转到屏幕外。 我试图从这个旋转我的盒子: 框不旋转

对此: 所需的框旋转

我的代码是

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: FractionallySizedBox(
          widthFactor: 0.5,
          heightFactor: 0.5,
          child: Container(
            color: Colors.grey,
            new RotationTransition(
              turns: AlwaysStoppedAnimation:(15 / 360),
              child: new FractionallySizedBox(
                widthFactor: 0.5,
                heightFactor: 0.5,
            ),)
          ),
        ),
      ),
    );
  }
}

我也希望它像第二张照片中那样被切断和倾斜。

您可以使用 2 个Transform 一个用于 x 轴(框向左移动),一个用于旋转:

import 'package:flutter/material.dart';
import 'dart:math' as math;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Transform.translate(
        offset: Offset(-120.0, 0.0),
        child: Transform.rotate(
          angle: math.pi / 5.0,
          child: Container(
            child: FractionallySizedBox(
              widthFactor: 0.5,
              heightFactor: 0.5,
              child: Container(
                color: Colors.grey,
              ),
            ),
          ),
        ),
      )),
    );
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM