123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- // import 'package:flutter/material.dart';
- // class AnimateFav extends StatefulWidget {
- // AnimateFav({Key? key, this.size}) : super(key: key);
- // final double size;
- // _AnimateFavState createState() => _AnimateFavState();
- // }
- // class _AnimateFavState extends State<AnimateFav>
- // with TickerProviderStateMixin {
- // AnimationController _controller_1;
- // AnimationController _controller_2;
- // Animation<double> _animation_1;
- // Animation<double> _animation_2;
- // Animation<double> curAnimation;
- // double rpx;
- // @override
- // void initState() {
- // super.initState();
- // _controller_1 =
- // AnimationController(vsync: this, duration: Duration(milliseconds: 300));
- // _controller_2 =
- // AnimationController(vsync: this, duration: Duration(milliseconds: 200));
- // _animation_1 = Tween(begin: 0.0, end: 1.3).animate(_controller_1)
- // ..addStatusListener((status) {
- // if (status == AnimationStatus.completed) {
- // _controller_2.forward(from: 0);
- // setState(() {
- // curAnimation = _animation_2;
- // });
- // }
- // })
- // ..addListener(() {
- // setState(() {});
- // });
- // _animation_2 = Tween(begin: 1.3, end: 1.0).animate(_controller_2)
- // ..addListener(() {
- // setState(() {});
- // });
- // curAnimation = _animation_1;
- // _controller_1.forward(from: 0);
- // }
- // @override
- // Widget build(BuildContext context) {
- // rpx = MediaQuery.of(context).size.width / 750;
- // return Center(
- // child: Icon(
- // Icons.favorite,
- // size: widget.size * curAnimation.value,
- // color: Colors.redAccent,
- // ));
- // }
- // }
- // class AnimatedUnFav extends StatefulWidget {
- // AnimatedUnFav({Key? key,required this.size}) : super(key: key);
- // final double size;
- // _AnimatedUnFavState createState() => _AnimatedUnFavState();
- // }
- // class _AnimatedUnFavState extends State<AnimatedUnFav> with TickerProviderStateMixin {
- // AnimationController _controller_1;
- // AnimationController _controller_2;
- // Animation<double> _animation_1;
- // Animation<double> _animation_2;
- // Animation<double> curAnimation;
- // Color curColor;
- // @override
- // void initState() {
- // super.initState();
- // curColor=Colors.redAccent;
- // _controller_1 =
- // AnimationController(vsync: this, duration: Duration(milliseconds: 100));
- // _controller_2 =
- // AnimationController(vsync: this, duration: Duration(milliseconds: 100));
- // _animation_1 = Tween(begin: 1.0, end: 1.2).animate(_controller_1)
- // ..addStatusListener((status) {
- // if (status == AnimationStatus.completed) {
- // _controller_2.forward(from: 0);
- // setState(() {
- // curAnimation = _animation_2;
- // curColor=Colors.grey[100];
- // });
- // }
- // })
- // ..addListener(() {
- // setState(() {});
- // });
- // _animation_2 = Tween(begin: 1.2, end: 1.0).animate(_controller_2)
- // ..addListener(() {
- // setState(() {});
- // });
- // curAnimation = _animation_1;
- // _controller_1.forward(from: 0);
- // }
- // @override
- // Widget build(BuildContext context) {
- // // rpx = MediaQuery.of(context).size.width / 750;
- // return Center(
- // child: Icon(
- // Icons.favorite,
- // size: widget.size * curAnimation.value,
- // color: curColor,
- // ));
- // }
- // }
- import 'dart:async';
- import 'package:douyin_demo/providers/recommend_provider.dart';
- import 'package:flutter/material.dart';
- // import 'package:provider/provider.dart';
- // class AnimatePositiveIcon extends StatefulWidget {
- // AnimatePositiveIcon({Key? key, required this.size, this.callback})
- // : super(key: key);
- // final double size;
- // final VoidCallback callback;
- // _AnimatePositiveIconState createState() => _AnimatePositiveIconState();
- // }
- // class _AnimatePositiveIconState extends State<AnimatePositiveIcon>
- // with TickerProviderStateMixin {
- // AnimationController _controller1;
- // AnimationController _controller2;
- // AnimationController _controller3;
- // Animation<double> _animation1;
- // Animation<double> _animation2;
- // Animation<double> _animation3;
- // Animation<double> curAnimation;
- // Color curColor;
- // @override
- // void initState() {
- // super.initState();
- // _controller1 =
- // AnimationController(vsync: this, duration: Duration(milliseconds: 150));
- // _controller2 =
- // AnimationController(vsync: this, duration: Duration(milliseconds: 200));
- // _controller3 =
- // AnimationController(vsync: this, duration: Duration(milliseconds: 60));
- // curColor = Colors.grey[100];
- // _animation1 = Tween(begin: 1.0, end: 0.0).animate(_controller1)
- // ..addListener(() {
- // setState(() {});
- // })
- // ..addStatusListener((status) {
- // if (status == AnimationStatus.completed) {
- // _controller2.forward(from: 0);
- // curAnimation = _animation2;
- // curColor = Colors.redAccent;
- // }
- // });
- // _animation2 = Tween(begin: 0.0, end: 1.2).animate(_controller2)
- // ..addListener(() {
- // setState(() {});
- // })
- // ..addStatusListener((status) {
- // if (status == AnimationStatus.completed) {
- // _controller3.forward(from: 0);
- // curAnimation = _animation3;
- // }
- // });
- // _animation3 = Tween(begin: 1.2, end: 1.0).animate(_controller3)
- // ..addListener(() {
- // setState(() {});
- // })
- // ..addStatusListener((status) {
- // if (status == AnimationStatus.completed && widget.callback != null) {
- // widget.callback();
- // }
- // });
- // // _controller1.forward(from: 0).then((_) {
- // // _controller2.forward(from: 0).then((_){
- // // _controller3.forward(from: 0);
- // // });
- // // });
- // curAnimation = _animation1;
- // _controller1.forward(from: 0);
- // }
- // @override
- // Widget build(BuildContext context) {
- // return Container(
- // child: Icon(
- // Icons.favorite,
- // size: widget.size * curAnimation.value,
- // color: curColor,
- // ),
- // );
- // }
- // }
- // class AnimateNegtiveIcon extends StatefulWidget {
- // AnimateNegtiveIcon(
- // {Key? key,
- // required this.size,
- // required this.icon,
- // required this.startColor,
- // required this.endColor,
- // this.callback})
- // : super(key: key);
- // final double size;
- // final IconData icon;
- // final VoidCallback callback;
- // final Color startColor;
- // final Color endColor;
- // _AnimateNegtiveIconState createState() => _AnimateNegtiveIconState();
- // }
- // class _AnimateNegtiveIconState extends State<AnimateNegtiveIcon>
- // with TickerProviderStateMixin {
- // AnimationController _controller1;
- // AnimationController _controller2;
- // Animation<double> _animation1;
- // Animation<double> _animation2;
- // Animation<double> curAnimation;
- // Color curColor;
- // @override
- // void initState() {
- // super.initState();
- // _controller1 =
- // AnimationController(vsync: this, duration: Duration(milliseconds: 200));
- // _controller2 =
- // AnimationController(vsync: this, duration: Duration(milliseconds: 200));
- // curColor = widget.startColor;
- // _animation1 = Tween(begin: 1.0, end: 1.2).animate(_controller1)
- // ..addListener(() {
- // setState(() {});
- // })
- // ..addStatusListener((status) {
- // if (status == AnimationStatus.completed) {
- // _controller2.forward(from: 0);
- // curAnimation = _animation2;
- // curColor = widget.endColor;
- // }
- // });
- // _animation2 = Tween(begin: 1.2, end: 1.0).animate(_controller2)
- // ..addListener(() {
- // setState(() {});
- // })
- // ..addStatusListener((status) {
- // if (status == AnimationStatus.completed && widget.callback != null) {
- // Timer(Duration(milliseconds: 100), () {
- // widget.callback();
- // });
- // }
- // });
- // // _controller1.forward(from: 0).then((_) {
- // // _controller2.forward(from: 0).then((_){
- // // _controller3.forward(from: 0);
- // // });
- // // });
- // curAnimation = _animation1;
- // }
- // @override
- // Widget build(BuildContext context) {
- // return IconButton(
- // padding: EdgeInsets.all(0),
- // onPressed: () {
- // _controller1.forward(from: 0);
- // },
- // icon: Icon(
- // widget.icon,
- // semanticLabel: "label",
- // size: widget.size * curAnimation.value,
- // color: curColor,
- // ));
- // }
- // }
- class AnimatedIconWidget extends StatefulWidget {
- AnimatedIconWidget(
- {Key? key,
- required this.animationList,
- required this.icon,
- required this.size,
- required this.callback,
- required this.callbackDelay,
- required this.provider})
- : super(key: key);
- final List<IconAnimationStage> animationList;
- final IconData icon;
- final VoidCallback callback;
- final double size;
- final RecommendProvider provider;
- final Duration callbackDelay;
- _AnimatedIconWidgetState createState() => _AnimatedIconWidgetState();
- }
- class _AnimatedIconWidgetState extends State<AnimatedIconWidget>
- with TickerProviderStateMixin {
- List<IconAnimationStage> anis = <IconAnimationStage>[];
- List<AnimationController> controllers = <AnimationController>[];
- List<Animation<double>> animations = <Animation<double>>[];
- late Animation<double> curAnim;
- late Color curColor;
- int curIndex = 0;
- List<bool> ifAdded = <bool>[];
- late double curSize;
- bool ifInit = true;
- loopAnimation(index) {
- curColor = curColor == null ? anis.first.color : curColor;
- if (index < controllers.length - 1) {
- if (!ifAdded[index]) {
- animations[index] = animations[index]
- ..addStatusListener((status) {
- if (status == AnimationStatus.completed) {
- curAnim = animations[index + 1];
- curColor = anis[index + 1].color;
- controllers[index + 1].forward(from: 0);
- loopAnimation(index + 1);
- }
- })
- ..addListener(() {
- setState(() {});
- });
- ifAdded[index] = true;
- }
- } else if (index == controllers.length - 1) {
- if (!ifAdded[index]) {
- animations[index] = animations[index]
- ..addStatusListener((status) {
- curColor = anis[index].color;
- if (status == AnimationStatus.completed) {
- if (widget.callbackDelay == null) {
- widget.callback();
- } else {
- Timer(widget.callbackDelay, () {
- widget.callback();
- });
- }
- }
- })
- ..addListener(() {
- setState(() {});
- });
- ifAdded[index] = true;
- }
- }
- }
- @override
- void initState() {
- super.initState();
- anis = widget.animationList;
- List.generate(anis.length, (index) {
- var curAni = anis[index];
- ifAdded.add(false);
- controllers.add(
- AnimationController(vsync: this, duration: anis[index].duration));
- animations.add(Tween(begin: curAni.start, end: curAni.end)
- .animate(controllers[index]));
- });
- curAnim = animations.first;
- loopAnimation(0);
- }
- @override
- Widget build(BuildContext context) {
- return IconButton(
- padding: EdgeInsets.all(0),
- onPressed: () {
- controllers.first.forward(from: 0);
- },
- icon: Icon(
- widget.icon,
- size: widget.size * curAnim.value,
- color: curColor,
- ),
- );
- }
- }
- class IconAnimationStage {
- double start;
- double end;
- Color color;
- Duration duration;
- IconAnimationStage(
- {required this.color,
- required this.duration,
- required this.end,
- required this.start});
- }
|