微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何对文本进行补间动画?从 Opacity =1 到 0 再回到 1 一键

如何解决如何对文本进行补间动画?从 Opacity =1 到 0 再回到 1 一键

如果前一个引用来自另一个类别,我已经使引用淡出和淡入。但是,如果报价来自同一类别,我将无法复制。

如果引用来自同一类别,如何使引用淡入淡出?

我觉得补间序列已经到了,但仍然无法得到结果。

感谢任何指导,谢谢!

AnimationController animationController;
  Animation<double> opacityAnimation;
  double opacity1 = 0.0;
///ditto for opacity2 and opacity3

String quotes1 = Quotes1[Random().nextInt(Quotes1.length)];

  void generateQuotes1() {
    setState(() {
      quotes1 = Quotes1[Random().nextInt(Quotes1.length)];
    });
  }


///ditto for Quotes2 and Quotes 3

  @override
  void initState() {
    super.initState();
    changeOpacity();

    animationController =
        AnimationController(vsync: this,duration: Duration(seconds: 3));
    animationController.forward();


    opacityAnimation = TweenSequence(
      <TweenSequenceItem<double>>[
        TweenSequenceItem<double>(
            tween: Tween<double>(begin: 1.0,end: 0.0)
                .chain(CurveTween(curve: Curves.easeInOutBack)),weight: 27),TweenSequenceItem<double>(
            tween: Tween<double>(begin: 0.0,end: 1.0)
                .chain(CurveTween(curve: Curves.easeInOutBack)),],).animate(
      animationController,);
  }

  @override
  void dispose() {
    animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold
...
           AnimatedOpacity(
                    opacity: opacity1 == 1.0 ? opacityAnimation.value : 0.0,duration: Duration(seconds: 1),child: Text(quotes1),///this shows the quote

ElevatedButton(
                  ...
                    onpressed: () {
                      generateQuotes1(); 
///This returns randomized quote from the list.
                      opacity1 = 1.0;
                      opacity2 = 0.0;
                      opacity3 = 0.0;
                    },),///ditto for quotes2 and quotes3
...
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。