ImageLoaderFactory class
A factory class for creating instances of ImageLoader.
The ImageLoaderFactory class is responsible for providing the appropriate
image loader implementation based on the specified ImageType. It allows
for flexible instantiation of image loaders and supports overriding the
default loader behavior for testing purposes.
This factory pattern is useful for managing multiple types of image loading strategies in a clean and maintainable way.
Methods:
-
ImageLoader getImageLoader(ImageType imageType):- Returns an instance of ImageLoader based on the specified
imageType. - Parameters:
imageType: An ImageType enum value that indicates the type of image loader to create (e.g., NETWORK, ASSET, SVG, FILE).
- Returns: An instance of ImageLoader corresponding to the requested image type.
- Throws:
- UnsupportedError if the specified
imageTypeis not supported.
- UnsupportedError if the specified
- Example:
ImageLoader loader = ImageLoaderFactory.getImageLoader(ImageType.NETWORK);
- Returns an instance of ImageLoader based on the specified
-
void setLoaderOverride(ImageLoader Function(ImageType) loader):- Allows for overriding the default loader implementation, useful for testing or custom behavior.
- Parameters:
loader: A function that takes an ImageType and returns an instance of ImageLoader.
-
void resetLoaderOverride():- Resets the loader override to the default implementation.
Usage:
The factory pattern allows clients to request specific image loaders without needing to know the concrete classes. This abstraction makes it easier to manage different loading strategies and facilitates unit testing by allowing developers to inject mock loaders as needed.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
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
Static Methods
-
getImageLoader(
ImageType imageType) → ImageLoader -
Returns an instance of ImageLoader based on the specified
imageType. -
resetLoaderOverride(
) → void - Resets the loader override to the default implementation.
-
setLoaderOverride(
ImageLoader loader(ImageType)) → void - Sets a custom loader implementation for testing purposes.