ResizeImage class
Instructs Flutter to decode the image at the specified dimensions instead of at its native size.
The width and height parameters refer to logical pixels.
Logical pixels have roughly the same visual size across devices, whereas physical pixels correspond to actual device hardware. The number of physical pixels per logical pixel is described by the ui.FlutterView.devicePixelRatio.
This allows finer control of the size of the image in ImageCache and is generally used to reduce the memory footprint of ImageCache.
The decoded image may still be displayed at sizes other than the cached size provided here.
This example shows how to size the image to half of the screen's width.
link
Image(
image: ResizeImage(
FileImage(File('path/to/image')),
width: MediaQuery.sizeOf(context).width ~/ 2, // Half of the screen's width.
),
);
- Inheritance
-
- Object
- ImageProvider<
ResizeImageKey> - ResizeImage
Constructors
-
ResizeImage(ImageProvider<
Object> imageProvider, {int? width, int? height, ResizeImagePolicy policy = ResizeImagePolicy.exact, bool allowUpscaling = false}) -
Creates an ImageProvider that decodes the image to the specified size.
const
Properties
- allowUpscaling → bool
-
Whether the width and height parameters should be clamped to the
intrinsic width and height of the image.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → int?
-
The height the image should decode to and cache.
final
-
imageProvider
→ ImageProvider<
Object> -
The ImageProvider that this class wraps.
final
- policy → ResizeImagePolicy
-
The policy that determines how width and height are interpreted.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- width → int?
-
The width the image should decode to and cache.
final
Methods
-
createStream(
ImageConfiguration configuration) → ImageStream -
Called by resolve to create the ImageStream it returns.
inherited
-
evict(
{ImageCache? cache, ImageConfiguration configuration = ImageConfiguration.empty}) → Future< bool> -
Evicts an entry from the image cache.
inherited
-
loadBuffer(
ResizeImageKey key, DecoderBufferCallback decode) → ImageStreamCompleter -
Converts a key into an ImageStreamCompleter, and begins fetching the
image.
override
-
loadImage(
ResizeImageKey key, ImageDecoderCallback decode) → ImageStreamCompleter -
Converts a key into an ImageStreamCompleter, and begins fetching the
image.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
obtainCacheStatus(
{required ImageConfiguration configuration, ImageErrorListener? handleError}) → Future< ImageCacheStatus?> -
Returns the cache location for the key that this ImageProvider creates.
inherited
-
obtainKey(
ImageConfiguration configuration) → Future< ResizeImageKey> -
Converts an ImageProvider's settings plus an ImageConfiguration to a key
that describes the precise image to load.
override
-
resolve(
ImageConfiguration configuration) → ImageStream -
Resolves this image provider using the given
configuration
, returning an ImageStream.inherited -
resolveStreamForKey(
ImageConfiguration configuration, ImageStream stream, ResizeImageKey key, ImageErrorListener handleError) → void -
Called by resolve with the key returned by obtainKey.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
resizeIfNeeded(
int? cacheWidth, int? cacheHeight, ImageProvider< Object> provider) → ImageProvider<Object> -
Composes the
provider
in a ResizeImage only whencacheWidth
andcacheHeight
are not both null.