flutter3.0学习笔记

RotatedBox

Preview
  • RotatedBox

RotatedBox

旋转盒子,将其子项旋转整数个四分之一圈。 RotatedBoxTransform.rotate功能相似,它们都可以对子组件进行旋转变换,但是有一点不同:RotatedBox的变换是在layout阶段,会影响子组件的位置和大小。

  • 构造函数
 const RotatedBox({
    super.key,
    required this.quarterTurns,////旋转的次数,每次旋转的度数只能是90度的整数倍
    super.child,
  }) 

例子:

import 'package:flutter/material.dart';

class RotatedBoxPage extends StatelessWidget {
  const RotatedBoxPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('RotatedBox'),),
      body: Center(
        child: Column(
          children: [
            RotatedBox(
              quarterTurns: 1,
              child: Container(
                width: 200,
                height: 200,
                color: Colors.red,
                alignment: Alignment.center,
                child: const Text(
                  '旋转1次',
                  style: TextStyle(color: Colors.white,fontSize: 30),
                ),
              ),
            ),
            RotatedBox(
              quarterTurns: 2,
              child: Container(
                width: 200,
                height: 200,
                color: Colors.blue,
                alignment: Alignment.center,
                child: const Text(
                  '旋转2次',
                  style: TextStyle(color: Colors.white,fontSize: 30),
                ),
              ),
            ),
            RotatedBox(
              quarterTurns: -1,
              child: Container(
                width: 200,
                height: 200,
                color: Colors.green,
                alignment: Alignment.center,
                child: const Text(
                  '旋转-1次',
                  style: TextStyle(color: Colors.white,fontSize: 30),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

Simulator Screen Shot - iPhone 14 Pro Max - 2022-12-22 at 17.56.49.png