Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initializing a FlareActor from different sources #16

Open
sroddy opened this issue Dec 12, 2018 · 4 comments
Open

Initializing a FlareActor from different sources #16

sroddy opened this issue Dec 12, 2018 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@sroddy
Copy link

sroddy commented Dec 12, 2018

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.

@luigi-rosso
Copy link
Contributor

luigi-rosso commented Dec 13, 2018

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.

@paldrian
Copy link

#48

@sultanmyrza
Copy link

feature we plan t

Any updates on this feature?

@darkpey
Copy link

darkpey commented Feb 25, 2020

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'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants