Image.network constructor

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

Creates a widget that displays an ImageStream obtained from the network.

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

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.

All network images are cached regardless of HTTP headers.

An optional headers argument can be used to send custom HTTP headers with the image request.

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 should 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.

In the case where the network image is on the Web platform, the cacheWidth and cacheHeight parameters are ignored as the web engine delegates image decoding to the web which does not support custom decode sizes.

Implementation

//
// TODO(garyq): We should eventually support custom decoding of network images
// on Web as well, see https://github.com/flutter/flutter/issues/42789.
Image.network(
  String src, {
  Key key,
  double scale = 1.0,
  this.frameBuilder,
  this.loadingBuilder,
  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,
  Map<String, String> headers,
  int cacheWidth,
  int cacheHeight,
}) : image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, NetworkImage(src, scale: scale, headers: headers)),
     assert(alignment != null),
     assert(repeat != null),
     assert(matchTextDirection != null),
     assert(cacheWidth == null || cacheWidth > 0),
     assert(cacheHeight == null || cacheHeight > 0),
     super(key: key);