首页 > 解决方案 > 按下按钮时播放 Flare 动画

问题描述

我在颤振中创建了一个 FloatingActionButton 来共享用户个人资料。每当用户单击该按钮时,我想显示一个小的耀斑动画。我正在使用此代码,但正在显示动画。动画文件是 Congratulations.flr

Tooltip(
                message: "Share with friends",
                child: new FloatingActionButton(
                  heroTag: null,

                  backgroundColor: primaryColor,
                  child: Icon(Icons.share),
                  onPressed: () {

                    FlareActor(
                      'assets/videos/Congratulations.flr',
                      alignment: Alignment.center,
                      fit: BoxFit.contain,
                      animation: 'animate',
                    );
                    shareUserProfile();
                  },
                ),
              ),

标签: flutterdart

解决方案


您必须将 FlareActor 放在 onPressed 方法之外您希望它出现的位置,然后在状态改变时启动它。

以下是有关如何执行此操作的好教程的链接

https://medium.com/flutter-community/better-animations-in-flutter-using-flare-an-experiment-bf9fa6c44f13

希望这对您有所帮助。


推荐阅读