如何将以下图标旋转180度?(我之后想要对其进行动画处理,
RotationTransition
不是我想要的选择)Icon(Icons.keyboard_arrow_down)
Transform
小部件来轻松实现。 Transform.rotate(
angle: pi, // in radians
child: Icon(Icons.keyboard_arrow_down),
);
AnimatedContainer
实现它呢? - WebMasterTransform
只是一个“普通”的小部件,你可以与任何你想要的东西一起使用。 :) - Miguel Ruivo以下是如何制作旋转动画,您还可以使用animationController在180°处停止动画:
import 'package:flutter/material.dart';
void main() {
runApp(new IconRotate());
}
class IconRotate extends StatefulWidget {
@override
_IconRotateState createState() => new _IconRotateState();
}
class _IconRotateState extends State<IconRotate>
with SingleTickerProviderStateMixin {
AnimationController animationController;
@override
void initState() {
super.initState();
animationController = new AnimationController(
vsync: this, //for using only a single AnimationController
duration: new Duration(seconds: 5),
);
animationController.repeat();
}
@override
Widget build(BuildContext context) {
return new Container(
alignment: Alignment.center,
color: Colors.white,
child: new AnimatedBuilder(
animation: animationController,
child: new Container(
height: 150.0,
width: 150.0,
child: Icon(Icons.keyboard_arrow_down),
),
builder: (BuildContext context, Widget _widget) {
return new Transform.rotate(
angle: animationController.value * 6.3,
child: _widget,
);
},
),
);
}
}
RotationTransition
不好?它确实可以在转换期间对子元素进行动画处理。 - pskinkAnimatedContainer
对我来说更加简洁。 - WebMasterMatrix4Tween
(https://github.com/flutter/flutter/blob/2783f8e2e1/packages/flutter/lib/src/widgets/implicit_animations.dart#L772),而Matrix4Tween
的官方文档指出:“目前此类仅适用于平移。” - pskinkMatrix4.identity()..rotateX(pi)
来旋转它,我的问题是旋转中心。 - WebMaster