ImageCraft class
A StatelessWidget that loads and displays images from various sources.
The ImageCraft widget is designed to facilitate the loading of images from different types of sources, such as network URLs, assets, SVGs, or files. It provides customizable options for loading, error handling, and display styles.
Parameters:
- path: A String representing the source path of the image. This can be a network URL, asset path, or file path, depending on the imageType.
- imageType: An ImageType enum value that specifies the type of image to be loaded (e.g., NETWORK, ASSET, SVG, FILE).
- fit: An optional BoxFit parameter that defines how the image should be inscribed into the allocated space. Defaults to BoxFit.cover.
- width: An optional double representing the width of the image. Defaults to 100.0.
- height: An optional double representing the height of the image. Defaults to 100.0.
- placeholder: An optional Widget that will be displayed while the image is being loaded. If not provided, a default loading indicator is used.
- errorWidget: An optional Widget that will be displayed if the image fails to load. If not provided, a default error indicator is used.
- preCacheAssets: A bool indicating whether to pre-cache assets before loading. Defaults to true.
Example Usage:
ImageCraft(
path: 'assets/image.png',
imageType: ImageType.ASSET,
fit: BoxFit.cover,
placeholder: CircularProgressIndicator(),
errorWidget: Icon(Icons.error),
);
Behavior: When the ImageCraft widget is built, it determines the appropriate image loader based on the provided imageType. If the image type is ASSET and preCacheAssets is true, it pre-caches the asset before loading it. The image loading process is handled asynchronously with a FutureBuilder, which displays the placeholder while loading and the error widget in case of failure.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- ImageCraft
Constructors
Properties
- errorWidget → Widget?
-
final
- fit → BoxFit
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → double
-
final
- imageType → ImageType
-
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- path → String
-
final
- placeholder → Widget?
-
final
- preCacheAssets → bool
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- width → double
-
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited