NetworkImageLoader class
A concrete implementation of ImageLoader that loads images from the network.
The NetworkImageLoader class extends the ImageLoader abstract class
and provides functionality to fetch images from a network URL, cache them
locally using the CachedManager, and display them in a widget.
Constructor:
NetworkImageLoader({CacheManager? cacheManager}):- Parameters:
cacheManager: An optional instance of CachedManager to handle local file caching. If not provided, a default instance will be created.
- Parameters:
Method:
Future<Widget> loadImage({...}):- Loads an image from a network URL or from the local cache if available.
- Parameters:
path: A String representing the URL of the image to load.fit: A BoxFit value that determines how the image should be resized to fit its container.width: A double representing the desired width of the image.height: A double representing the desired height of the image.placeholder: An optional Widget to be displayed while the image is loading. Defaults to null if not provided.errorWidget: An optional Widget to be displayed if the image fails to load. Defaults to null if not provided.
- Returns: A Future<Widget> that resolves to a widget displaying the loaded image, or a placeholder/error widget as applicable.
- Example:
Widget imageWidget = await networkImageLoader.loadImage( path: 'https://example.com/image.png', fit: BoxFit.cover, width: 200.0, height: 100.0, placeholder: CircularProgressIndicator(), errorWidget: Text('Failed to load image'), );
Error Handling:
If the image cannot be downloaded or the server returns an error code,
the method will return the specified errorWidget or an ErrorPlaceholder
widget if no error widget is provided.
- Inheritance
-
- Object
- ImageLoader
- NetworkImageLoader
Constructors
- NetworkImageLoader({CachedManager? cacheManager})
- Creates a NetworkImageLoader instance with an optional cache manager.
Properties
- cacheManager → CachedManager
-
The cache manager instance used for handling cached images.
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
-
loadImage(
{required String path, required BoxFit fit, required double width, required double height, Widget? placeholder, Widget? errorWidget}) → Future< Widget> -
Loads an image from a network URL or from the local cache if available.
override
-
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