2d-inc / Flare-Flutter

Load and get full control of your Rive files in a Flutter project using this library.
https://rive.app/
MIT License
2.55k stars 469 forks source link

Fixing flr file load failed in flutter plugin. #130

Closed lionoggo closed 3 years ago

lionoggo commented 5 years ago

If we use Flare animation in the flutter-plugin project, an exception will be thrown that the resource failed to load, as shown below:

E/flutter (15211): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Unable to load asset: assets/Filip.flr
E/flutter (15211): #0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:229:7)
E/flutter (15211): <asynchronous suspension>
E/flutter (15211): #1      FlareCacheAsset.load (package:flare_flutter/flare_cache_asset.dart:18:20)
E/flutter (15211): #2      Cache.getAsset (package:flare_flutter/cache.dart:55:15)
E/flutter (15211): <asynchronous suspension>

The root cause of the problem is: no package name is specified for the resource.We solve this problem by specifying a package name for the resource, as shown below:

    FlareActor(
      "assets/Filip.flr",
      alignment: Alignment.center,
      fit: BoxFit.contain,
      animation: _animationName,
      package: 'simple_plugin',
    );

At the same time, I also added a new demo project:simple-plugin.

OOMROO commented 5 years ago

It's great.

OOMROO commented 5 years ago

FlareActor( "packages/pluginname/assets/Filip.flr", alignment: Alignment.center, fit: BoxFit.contain, animation: _animationName,

);

it's ok