UniversalImage class

A widget to display all image types for all platforms.

It does supports JPEG, PNG, GIF, Animated GIF, WebP, Animated WebP, BMP, and WBMP from Image

For SVG, it uses flutter_svg

It also supports caching image with extended_image

It can handle all providers without specifying network, assets or file, just use imageUri

It can work with Icons font & memory image as well

Example:

Assets provider: UniversalImage('assets/image.png')

File provider: UniversalImage('/user/app/image.png')

Network provider: UniversalImage('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg')

Icon provider: UniversalImage.icon(Icons.add)

Memory provider: UniversalImage('base64://base64string')

Inheritance

Constructors

UniversalImage(String imageUri, {Key? key, double scale = 1.0, IconData? icon, ImageFrameBuilder? frameBuilder, ImageErrorWidgetBuilder? errorBuilder, String? semanticLabel, bool excludeFromSemantics = false, double? width, double? height, Color? color, BlendMode? colorBlendMode, BoxFit? fit, Alignment alignment = Alignment.center, ImageRepeat repeat = ImageRepeat.noRepeat, Rect? centerSlice, bool matchTextDirection = false, bool gaplessPlayback = false, bool isAntiAlias = false, FilterQuality filterQuality = FilterQuality.low, int? cacheWidth, int? cacheHeight, bool allowDrawingOutsideViewBox = false, bool svgSkiaMode = false, double? size, TextDirection? textDirection, Widget? placeholder, Widget? errorPlaceholder, bool cache = true, bool enableMemoryCache = true, bool clearMemoryCacheIfFailed = true, bool clearMemoryCacheWhenDispose = false, String assetPrefix = 'assets', double? compressionRatio, int? maxBytes, ImageEngine imageEngine = ImageEngine.extendedImage, Object? heroTag, ColorFilter? colorFilter})
Create image widet base on uri
const
UniversalImage.icon(IconData? icon, {Key? key, String imageUri = '', double scale = 1.0, ImageFrameBuilder? frameBuilder, ImageErrorWidgetBuilder? errorBuilder, String? semanticLabel, bool excludeFromSemantics = false, double? width, double? height, Color? color, BlendMode? colorBlendMode, BoxFit? fit, Alignment alignment = Alignment.center, ImageRepeat repeat = ImageRepeat.noRepeat, Rect? centerSlice, bool matchTextDirection = false, bool gaplessPlayback = false, bool isAntiAlias = false, FilterQuality filterQuality = FilterQuality.low, int? cacheWidth, int? cacheHeight, bool allowDrawingOutsideViewBox = false, bool svgSkiaMode = false, double? size, TextDirection? textDirection, Widget? placeholder, Widget? errorPlaceholder, bool cache = true, bool enableMemoryCache = true, bool clearMemoryCacheIfFailed = true, bool clearMemoryCacheWhenDispose = false, String assetPrefix = 'assets', double? compressionRatio, int? maxBytes, ImageEngine imageEngine = ImageEngine.extendedImage, Object? heroTag, ColorFilter? colorFilter})
Create image widet base on icon data

Properties

alignment Alignment
Represents the alignment of the image within its container.
final
allowDrawingOutsideViewBox bool
A boolean property that determines whether the image can be drawn outside its viewBox. Default is false.
final
assetPrefix String
The prefix used for asset images.
final
cache bool
A boolean property that determines whether the image should be cached. Default is true.
final
cacheHeight int?
An optional integer property that sets the height of the image cache.
final
cacheWidth int?
An optional integer property that sets the width of the image cache.
final
centerSlice Rect?
An optional Rect property that defines the center slice of the image.
final
clearMemoryCacheIfFailed bool
A boolean property that determines whether to clear the memory cache if the image fails to load. Default is true.
final
clearMemoryCacheWhenDispose bool
A boolean property that determines whether to clear the memory cache when the widget is disposed. Default is false.
final
color Color?
An optional Color property that sets the color of the image.
final
colorBlendMode BlendMode?
An optional BlendMode property that defines how the image color should blend with the background.
final
colorFilter ColorFilter?
An optional ui.ColorFilter property that sets the color filter of the image.
final
compressionRatio double?
An optional double property that sets the image compression ratio.
final
enableMemoryCache bool
A boolean property that determines whether the memory cache is enabled. Default is true.
final
errorBuilder ImageErrorWidgetBuilder?
An optional ImageErrorWidgetBuilder property that defines the error widget when the image fails to load.
final
errorPlaceholder Widget?
An optional Widget property that defines the error placeholder widget displayed when the image fails to load.
final
excludeFromSemantics bool
A boolean property that determines whether the image is excluded from semantics. Default is false.
final
filterQuality FilterQuality
A FilterQuality property that sets the quality of image filtering.
final
fit BoxFit?
An optional BoxFit property that defines how the image should fit within its container.
final
frameBuilder ImageFrameBuilder?
An optional ImageFrameBuilder property that defines the frame builder for the image.
final
gaplessPlayback bool
A boolean property that determines whether the image should have gapless playback. Default is false.
final
hashCode int
The hash code for this object.
no setterinherited
height double?
An optional double property that sets the height of the image.
final
heroTag Object?
An optional Object property that sets the hero tag for the image.
final
icon IconData?
The icon data, if the resource is an icon.
final
imageEngine ImageEngine
An ImageEngine property that sets the image engine.
final
imageUri String
Image uri, it can be http url, assets file path (assets path must start with assets) or local file
final
isAntiAlias bool
A boolean property that determines whether the image should be anti-aliased. Default is false.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
matchTextDirection bool
Indicates whether the image should match the text direction or not.
final
maxBytes int?
An optional integer property that sets the maximum number of bytes for the image.
final
placeholder Widget?
An optional Widget property that defines the placeholder widget displayed while the image is loading.
final
repeat ImageRepeat
Determines how the image should be repeated.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scale double
The scale to apply to the image.
final
semanticLabel String?
The semantic label for the image, used for accessibility.
final
size double?
The size of the icon, if the resource is an icon.
final
svgSkiaMode bool
Indicates whether the image should be rendered using Skia for SVGs.
final
textDirection TextDirection?
The text direction for the icon, if the resource is an icon.
final
width double?
The width of the image.
final

Methods

build(BuildContext context) Widget
Build 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}) 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

Static Methods

clearCache() Future<void>
Clear cache from memory and disk
precache(BuildContext context, String imageUri, {String assetPrefix = 'assets'}) Future<void>
Precache the image