按下按钮即可播放Flare动画

时间:2020-10-08 10:33:19

标签: flutter dart

我在flutter中创建了一个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();
                  },
                ),
              ),

1 个答案:

答案 0 :(得分:0)

您必须将FlareActor放在要显示它的位置onPressed方法之外,然后在状态更改后启动它。

下面是有关如何执行此操作的优秀教程的链接

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

希望这对您有所帮助。