简体   繁体   English

在 flutter web 中运行 flare/rive animation 时出错

[英]Error running flare/ rive animation in flutter web

I have developed an app now using the same animation in the flutter web. But its throwing error.我现在开发了一个应用程序,在 flutter web 中使用相同的 animation。但是它抛出错误。 I have downloaded the binary file of flutter and provided it to the flare but it doesn't work.我已经下载了flutter的二进制文件并提供给flare但是没有用。 The same code works well in android but throwing error in flutter web Plzz help.相同的代码在 android 中运行良好,但在 flutter 中抛出错误 web Plzz 帮助。 Error:错误:

Error: [object Event]


    at Object.createErrorWithStack (http://localhost:62576/dart_sdk.js:4789:12)
    at Object._rethrow (http://localhost:62576/dart_sdk.js:35903:16)
    at async._AsyncCallbackEntry.new.callback
    (http://localhost:62576/dart_sdk.js:35899:13)
    at Object._microtaskLoop (http://localhost:62576/dart_sdk.js:35759:13)
    at _startMicrotaskLoop (http://localhost:62576/dart_sdk.js:35765:13)
    at http://localhost:62576/dart_sdk.js:31707:9

Code:代码:


class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  String animationName = "forward";
  bool paused;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    animationName = "forward";
    paused = false;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: FlareActor(
        "flare_truck.flr",
        animation: animationName,
        fit: BoxFit.fitHeight,
        alignment: Alignment(0, 0),
        callback: (str) {
          setState(
            () {
              animationName = "upDown";
            },
          );
        },
      ),
    );
  }
}

There is an open Github issue on Flare animations working on iOS and Android but breaking on web here .在 iOS 和 Android 上工作但在 web 上中断的 Flare 动画有一个开放的 Github问题

A member of the Flare/Rive team has said the following about the issue: Flare/Rive 团队的一名成员就此问题发表了以下看法:

"There are two issues here but the fundamental one is that Flutter Web does not support image shaders for triangle meshes, which is how Flare renders images. Unfortunately, that means that Flare images won't work in Flutter Web right now. What we can do on our side is disable them from drawing so you don't get exceptions." “这里有两个问题,但最根本的一个是 Flutter Web 不支持三角形网格的图像着色器,这就是 Flare 渲染图像的方式。不幸的是,这意味着 Flare 图像现在无法在 Flutter Web 中工作。我们能做什么在我们这边做的是禁止他们绘图,这样你就不会得到例外。”

You could follow the Github issue for any specific updates on this.您可以关注 Github 问题以获取有关此的任何特定更新。

While this doesn't help much there is a workaround you could try using RepaintBoundary for Stack and Flare issues.虽然这没有太大帮助,但您可以尝试使用RepaintBoundary解决 Stack 和 Flare 问题。 You can check the StackOverflow answer here .您可以在此处查看 StackOverflow 答案。

I was facing the same problem, i found out that if you use any images within your animation, it doesn't work well with flutter web, so instead of using your images as.png.我遇到了同样的问题,我发现如果你在 animation 中使用任何图像,它不能很好地与 flutter web 一起使用,所以不要使用你的图像 as.png。 convert all images to paths using illustrator to.svg file format使用 illustrator 将所有图像转换为 .svg 文件格式的路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM