Image.memory constructor

Image.memory(
  1. Uint8List bytes,
  2. {Key key,
  3. double scale: 1.0,
  4. ImageFrameBuilder frameBuilder,
  5. String semanticLabel,
  6. bool excludeFromSemantics: false,
  7. double width,
  8. double height,
  9. Color color,
  10. BlendMode colorBlendMode,
  11. BoxFit fit,
  12. AlignmentGeometry alignment: Alignment.center,
  13. ImageRepeat repeat: ImageRepeat.noRepeat,
  14. Rect centerSlice,
  15. bool matchTextDirection: false,
  16. bool gaplessPlayback: false,
  17. FilterQuality filterQuality: FilterQuality.low,
  18. int cacheWidth,
  19. int cacheHeight}
)

Creates a widget that displays an ImageStream obtained from a Uint8List.

The bytes, scale, and repeat arguments must not be null.

This only accepts compressed image formats (e.g. PNG). Uncompressed formats like rawRgba (the default format of ui.Image.toByteData) will lead to exceptions.

Either the width and height arguments should be specified, or the widget should be placed in a context that sets tight layout constraints. Otherwise, the image dimensions will change as the image is loaded, which will result in ugly layout changes.

Use filterQuality to change the quality when scaling an image. Use the FilterQuality.low quality setting to scale the image, which corresponds to bilinear interpolation, rather than the default FilterQuality.none which corresponds to nearest-neighbor.

If excludeFromSemantics is true, then semanticLabel will be ignored.

If cacheWidth or cacheHeight are provided, it indicates to the engine that the image must be decoded at the specified size. The image will be rendered to the constraints of the layout or width and height regardless of these parameters. These parameters are primarily intended to reduce the memory usage of ImageCache.

Implementation

Image.memory(
  Uint8List bytes, {
  Key key,
  double scale = 1.0,
  this.frameBuilder,
  this.semanticLabel,
  this.excludeFromSemantics = false,
  this.width,
  this.height,
  this.color,
  this.colorBlendMode,
  this.fit,
  this.alignment = Alignment.center,
  this.repeat = ImageRepeat.noRepeat,
  this.centerSlice,
  this.matchTextDirection = false,
  this.gaplessPlayback = false,
  this.filterQuality = FilterQuality.low,
  int cacheWidth,
  int cacheHeight,
}) : image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, MemoryImage(bytes, scale: scale)),
     loadingBuilder = null,
     assert(alignment != null),
     assert(repeat != null),
     assert(matchTextDirection != null),
     assert(cacheWidth == null || cacheWidth > 0),
     assert(cacheHeight == null || cacheHeight > 0),
     super(key: key);