82b921d09afc767a1a3867f2dc537d57.gif

说明

旋转子控件动画

示例演示

import 'package:flutter/material.dart';

///旋转动画
class RotationTransitionPage extends StatefulWidget {
  @override
  _RTState createState() => _RTState();
}

class _RTState extends State<RotationTransitionPage>with SingleTickerProviderStateMixin {
  Animation<double> animation; //动画对象
  AnimationController controller; //动画控制器
  @override
  initState() {
    super.initState();
    controller =
        AnimationController(duration: const Duration(seconds: 6), vsync: this);

    animation = CurvedAnimation(parent: controller, curve: ElasticOutCurve());

    animation.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        controller.reverse();
      } else if (status == AnimationStatus.dismissed) {
        controller.forward();
      }
    });
    ///动画开始
    controller.forward();
 
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Center(child: Text("RotationTransition简单使用")),
          elevation: 0.0,
        ),
        body: Center(
          child: Container(
            width: 1.0,
            height: 400,
            decoration: BoxDecoration(
              color: Colors.yellow,
            ),
            child: RotationTransition(
// turns: controller,///可以打开这个注释,直接利用controller来实现旋转
              turns: animation,
              child: Container(
                width: 1.0,
                height: 400,
                decoration: BoxDecoration(
                  color: Colors.red,
                ),
              ),
            ),
          ),
        ));
  }

  @override
  dispose() {
    //路由销毁时需要释放动画资源
    controller.dispose();
    super.dispose();
  }
}

效果:

0351d95ca42edc4e68eb2bb6cfb3eed9.gif

  码上加油站

  一起来加油

长按扫码关注

5bbe294bb39a420a9e1dcda9eab46991.png记得点个在看哦!
Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐