首页 > 解决方案 > 如何让 RotateTransition 将我的小部件旋转一半(180 度)

问题描述

如何使用 RoatateTransition 使小部件旋转到特定程度:我的代码如下所示:

AnimationController _animationController;
  
  @override
  void initState() {
    super.initState();
    _animationController = AnimationController(vsync: this, duration: Duration(seconds: 1));
    _animationController.repeat();
  }

  RotationTransition(
    turns: this.animationController,
    child: Icon(Icons.arrow_drop_down_sharp, color: Colors.white, size: 25,)
 )

但我的问题是代码不断旋转,希望让它旋转到特定的角度并反转回来。

标签: flutter

解决方案


你需要定义像

 AnimationController  _animationController = AnimationController(
          duration: const Duration(seconds: 1),
          vsync: this,
          value: 0,
          lowerBound: 0,
          upperBound: 0.5
      );
 Animation<double>  _animation = CurvedAnimation(parent: _controller, curve: Curves.linear);

 RotationTransition(
    turns: _animation,
    child: Icon(Icons.arrow_drop_down_sharp, color: Colors.white, size: 25,)
 )

推荐阅读