AnimatedRotation
RotationTransition 的隐式动画版本,当提供的角度改变时,它会自动随时间过渡旋转。
安装
从 pub 获取。
将依赖项添加到你的pubspec.yaml
dependencies:
animated_rotation: ^1.0.0
保存pubspec.yaml文件后,在你的根文件夹中运行 flutter pub get
用法
这是一个计数器应用示例,文本根据计数进行旋转
import 'package:animated_rotation/animated_rotation.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyHomePage());
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("AnimatedRotation example"),
),
body: Center(
child: AnimatedRotation(
angle: _counter,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
_counter++;
});
},
tooltip: 'Increment',
child: Icon(Icons.add),
),
),
);
}
}
示例图片

示例gif
