FlameNetworkAssets<T> class
abstract
FlameNetworkAssets is a class similar to Flame's assets classes (like
Images
for example), but instead of loading assets from the assets bundle,
it loads from networks urls.
By default, FlameNetworkAssets uses the http.get
method to make the
requests. It can be customized by passing a different GetAssetFunction to
the get
argument on the constructor.
FlameNetworkAssets also will automatically cache files in a two layer system.
The first layer is an in-memory cache, handled by an internal MemoryCache
,
while the second one is the device's own file system, where images are
cached in the application document directory, which by default is provided
by path_providers' getApplicationDocumentsDirectory
method, and can
be customized using the getAppDirectory
argument in the constructor.
When an asset is requested, FlameAssetResponse will first check on its cache layers before making the http request, if both layer are cache miss, then the request is made and both layers set with the response.
Another important note about the cache layers is that the first layer, is a per instance cache, while the local storage is an app global cache. This means that two different FlameAssetResponse instances will have the same local storage cache, but not the same memory cache.
Note that the local storage layer is not present when running on web since that platform doesn't really have a file system. The browser caching will work as a similar replacement for this layer, though that can't be controlled by this package, make sure that the server where the images are being fetched returns the correct cache header to make the browser cache the assets.
Each cache layer can be disabled by the cacheInMemory or cacheInStorage argument on the constructor.
- Implementers
Constructors
-
FlameNetworkAssets.new({required DecodeAssetFunction<
T> decodeAsset, required EncodeAssetFunction<T> encodeAsset, GetAssetFunction? get, GetAppDirectoryFunction? getAppDirectory, bool cacheInMemory = true, bool cacheInStorage = true}) -
FlameNetworkAssets is a class similar to Flame's assets classes (like
Images
for example), but instead of loading assets from the assets bundle, it loads from networks urls.
Properties
- cacheInMemory → bool
-
Flag indicating if files will be cached in memory.
final
- cacheInStorage → bool
-
Flag indicating if files will be cached in the local storage.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
load(
String url, {Map< String, String> ? headers}) → Future<T> - Loads the asset from the given url.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited