Flare-flutter: Initializing a FlareActor from different sources

Created on 12 Dec 2018  路  4Comments  路  Source: 2d-inc/Flare-Flutter

Right now a FlareActor can be initialized only with a path of a file from the rootBundle.
I think it would be really useful to support a few other loading modes (e.g. network, string, bytes, ...)
I saw that the FlutterActor is the thing that actually is being loaded async. one possibile approach is to have a constructor with the following signature

FlareActor.asyncBytes(Future<Uint8List> Function() loadBytes, {void Function() onCancel});

The onCancel function would be useful in order to abort a potentially long running loading operation (for example from the network) if the render object has been disposed in the meantime.

enhancement

Most helpful comment

Try this:

class FileFlare extends AssetProvider {
  final String name;
  FileFlare(this.name);

  @override
  Future<ByteData> load() async {
    final cacheDir = await getTemporaryDirectory();
    final file = File('${cacheDir.path}/$name');
    final bytes = file.readAsBytesSync();
    return ByteData.view(bytes.buffer);
  }
}

Usage:

FlareActor.asset(FileFlare('hello.flr'));

All 4 comments

This is dead on. We definitely want to support more loading paths, we just haven't made a nice API for them yet. The network load is a big one for us as loading directly from your source file on 2Dimensions.com is a feature we plan to support soon.

48

feature we plan t

Any updates on this feature?

Try this:

class FileFlare extends AssetProvider {
  final String name;
  FileFlare(this.name);

  @override
  Future<ByteData> load() async {
    final cacheDir = await getTemporaryDirectory();
    final file = File('${cacheDir.path}/$name');
    final bytes = file.readAsBytesSync();
    return ByteData.view(bytes.buffer);
  }
}

Usage:

FlareActor.asset(FileFlare('hello.flr'));
Was this page helpful?
0 / 5 - 0 ratings

Related issues

gabber235 picture gabber235  路  6Comments

Nijinsha picture Nijinsha  路  7Comments

MrSagarShah picture MrSagarShah  路  3Comments

stx picture stx  路  6Comments

FredslundMagnus picture FredslundMagnus  路  6Comments