Seth Ladd Seth Ladd - 2 months ago 38
Dart Question

How do I change or replace the ImageCache in Flutter?

I want to change the behavior of the ImageCache in my Flutter app. For example, I want to experiment with different eviction strategies. Or, I simply want zero caching (for experimenting).

How do I replace to change the ImageCache?

Answer Source

Create a class that inherits from WidgetsFlutterBinding. Override createImageCache on that class to return the ImageCache implementation of your choice. Call the constructor on that class before you call runApp.

There's one binding per application. The first binding (subclass of BindingBase) that is created gets to be that binding. Calling runApp() instantiates the WidgetsFlutterBinding binding, which is usually what you want. One of the classes that WidgetsFlutterBinding mixes in, the PaintingBinding, introduces createImageCache as a way to let you override the image cache. It calls that method, and sets the global imageCache to whatever that method returns.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download