Techniques and considerations to cache a Rive File in Flutter.
.riv
file should load quickly and managing the RiveFile
yourself is not necessary. But if you intend to use the same .riv
file in multiple parts of your application, or even on the same screen, it might be advantageous to load the file once and keep it in memory.
RiveAnimation.direct()
constructor:
RiveFile
is kept alive in state and shared to other widgets is up to you and your preferred state management solution. One approach can be to wait for the Rive file to load in main
, or during the startup screen, and using the Provider package to expose the data to the whole application.
Or if the animation is only needed in a nested section of your application, then it might be preferable to delay loading the animation until necessary.
RiveAnimation
widgets.
You can make use of Flutter DevTools’ memory tooling for additional investigation if needed or desired.
RiveAnimation.network(url)
. However, similar considerations apply to a network asset regarding memory and sharing a Rive file across multiple widgets/pages.
The following can be used to load a Rive file over the network:
riveFile
can be passed to RiveAnimation.direct
.