Image.memory constructor Null safety

  1. Uint8List bytes,
  2. {Key? key,
  3. double scale = 1.0,
  4. ImageFrameBuilder? frameBuilder,
  5. ImageErrorWidgetBuilder? errorBuilder,
  6. String? semanticLabel,
  7. bool excludeFromSemantics,
  8. double? width,
  9. double? height,
  10. Color? color,
  11. Animation<double>? opacity,
  12. BlendMode? colorBlendMode,
  13. BoxFit? fit,
  14. AlignmentGeometry alignment,
  15. ImageRepeat repeat,
  16. Rect? centerSlice,
  17. bool matchTextDirection,
  18. bool gaplessPlayback,
  19. bool isAntiAlias,
  20. FilterQuality filterQuality,
  21. int? cacheWidth,
  22. int? cacheHeight}

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

The bytes argument specifies encoded image bytes, which can be encoded in any of the following supported image formats: JPEG, PNG, GIF, Animated GIF, WebP, Animated WebP, BMP, and WBMP. Additional formats may be supported by the underlying platform. Flutter will attempt to call platform API to decode unrecognized formats, and if the platform API supports decoding the image Flutter will be able to render it.

The scale argument specifies the linear scale factor for drawing this image at its intended size and applies to both the width and the height. For example, if this is 2.0, it means that there are four image pixels for every one logical pixel, and the image's actual width and height (as given by the dart:ui.Image.width and dart:ui.Image.height properties) are double the height and width that should be used when painting the image (e.g. in the arguments given to Canvas.drawImage).

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 dart: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 specify the rendering quality of the image.

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.


  Uint8List bytes, {
  Key? key,
  double scale = 1.0,
  this.excludeFromSemantics = false,
  this.alignment =,
  this.repeat = ImageRepeat.noRepeat,
  this.matchTextDirection = false,
  this.gaplessPlayback = false,
  this.isAntiAlias = 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),
     assert(isAntiAlias != null),
     super(key: key);