flutter 逆时针旋转
时间: 2023-07-29 12:09:41 浏览: 121
要将窗口逆时针旋转,只需要更改旋转角度的符号即可。以下是修改后的示例代码:
```dart
import 'package:flutter/material.dart';
void main() => runApp(RotateWindowApp());
class RotateWindowApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Rotate Window Demo',
home: RotateWindow(),
);
}
}
class RotateWindow extends StatefulWidget {
@override
_RotateWindowState createState() => _RotateWindowState();
}
class _RotateWindowState extends State<RotateWindow> {
double angle = 0;
void _rotateWindow() {
setState(() {
angle = angle - 45;
});
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: _rotateWindow,
child: Transform.rotate(
angle: angle * 3.14 / 180,
child: Container(
height: 200,
width: 200,
color: Colors.blue,
child: Center(
child: Text(
'Click to Rotate',
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
),
),
),
);
}
}
```
在这个示例中,我们将 `_rotateWindow` 函数中的 `angle` 值减去 45 度,以实现逆时针旋转。注意,我们在 `Transform.rotate` widget 中使用的角度值仍然是正值,但是 `angle` 变量的符号已经更改。
阅读全文