如何预缓存颤动闪光动画

问题描述 投票:0回答:1

我有一个耀斑加载动画,需要花费一些时间来加载。有没有一种方法可以预缓存抖动动画?

final AssetProvider assetProvider = AssetFlare(bundle: rootBundle, name: 'assets/animations/loop.flr');
cachedActor(assetProvider);

这是缓存参与者的代码吗?然后如何加载缓存的动画?

flutter flutter-animation
1个回答
0
投票

来自https://github.com/2d-inc/Flare-Flutter/issues/180#issuecomment-550584347您可以使用FlareCacheBuilder帮助您为应用的某些部分预加载flr文件

代码段

Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey,
      appBar: AppBar(title: Text(widget.title)),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: [
            Expanded(
              child: FlareCacheBuilder(
                ["assets/Filip.flr"],
                builder: (BuildContext context, bool isWarm) {
                  return !isWarm
                      ? Container(child: Text("Loading..."))
                      : FlareActor(
                          "assets/Filip.flr",
                          alignment: Alignment.center,
                          fit: BoxFit.contain,
                          animation: _animationName,
                        );
                },
              ),
            )
          ],
        ),
      ),
    );
  }
© www.soinside.com 2019 - 2024. All rights reserved.