flutterflare

Can we provide URL instead asset In FlareActor in flutter?


Is it possible to give firebase Url instead of asset in flareActor in flutter?


Solution

  • When you see something that takes a URL that points to data as a parameter, it must being doing a network request at some point to obtain that data. Since there is no URL constructor for a FlareActor, do your own network request with the http package. Add the appropriate version to your pubspec.yaml dependencies.

    dependencies:
      http: ^0.12.2
    

    Import the package into the file where you need the FlareActor. Do a get request to obtain the data and pass the data to the FlareActor.memory constructor.

    var resp = await get(url);
    
    FlareActor actor = FlareActor.memory(resp.bodyBytes);
    

    Wrap the above code in a Future function and use a FutureBuilder in build to show your flare actor on the screen once it's ready.