FadeInImage.assetNetwork constructor Null safety

FadeInImage.assetNetwork(
  1. {Key? key,
  2. required String placeholder,
  3. ImageErrorWidgetBuilder? placeholderErrorBuilder,
  4. required String image,
  5. ImageErrorWidgetBuilder? imageErrorBuilder,
  6. AssetBundle? bundle,
  7. double? placeholderScale,
  8. double imageScale = 1.0,
  9. bool excludeFromSemantics,
  10. String? imageSemanticLabel,
  11. Duration fadeOutDuration,
  12. Curve fadeOutCurve,
  13. Duration fadeInDuration,
  14. Curve fadeInCurve,
  15. double? width,
  16. double? height,
  17. BoxFit? fit,
  18. AlignmentGeometry alignment,
  19. ImageRepeat repeat,
  20. bool matchTextDirection,
  21. int? placeholderCacheWidth,
  22. int? placeholderCacheHeight,
  23. int? imageCacheWidth,
  24. int? imageCacheHeight}
)

Creates a widget that uses a placeholder image stored in an asset bundle while loading the final image from the network.

The placeholder argument is the key of the image in the asset bundle.

The image argument is the URL of the final image.

The placeholderScale and imageScale arguments are passed to their respective ImageProviders (see also ImageInfo.scale).

If placeholderScale is omitted or is null, pixel-density-aware asset resolution will be attempted for the placeholder image. Otherwise, the exact asset specified will be used.

If placeholderCacheWidth, placeholderCacheHeight, imageCacheWidth, or imageCacheHeight are provided, it indicates to the engine that the respective 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.

The placeholder, image, imageScale, fadeOutDuration, fadeOutCurve, fadeInDuration, fadeInCurve, alignment, repeat, and matchTextDirection arguments must not be null.

See also:

  • new Image.asset, which has more details about loading images from asset bundles.
  • new Image.network, which has more details about loading images from the network.

Implementation

FadeInImage.assetNetwork({
  Key? key,
  required String placeholder,
  this.placeholderErrorBuilder,
  required String image,
  this.imageErrorBuilder,
  AssetBundle? bundle,
  double? placeholderScale,
  double imageScale = 1.0,
  this.excludeFromSemantics = false,
  this.imageSemanticLabel,
  this.fadeOutDuration = const Duration(milliseconds: 300),
  this.fadeOutCurve = Curves.easeOut,
  this.fadeInDuration = const Duration(milliseconds: 700),
  this.fadeInCurve = Curves.easeIn,
  this.width,
  this.height,
  this.fit,
  this.alignment = Alignment.center,
  this.repeat = ImageRepeat.noRepeat,
  this.matchTextDirection = false,
  int? placeholderCacheWidth,
  int? placeholderCacheHeight,
  int? imageCacheWidth,
  int? imageCacheHeight,
}) : assert(placeholder != null),
     assert(image != null),
     placeholder = placeholderScale != null
       ? ResizeImage.resizeIfNeeded(placeholderCacheWidth, placeholderCacheHeight, ExactAssetImage(placeholder, bundle: bundle, scale: placeholderScale))
       : ResizeImage.resizeIfNeeded(placeholderCacheWidth, placeholderCacheHeight, AssetImage(placeholder, bundle: bundle)),
     assert(imageScale != null),
     assert(fadeOutDuration != null),
     assert(fadeOutCurve != null),
     assert(fadeInDuration != null),
     assert(fadeInCurve != null),
     assert(alignment != null),
     assert(repeat != null),
     assert(matchTextDirection != null),
     image = ResizeImage.resizeIfNeeded(imageCacheWidth, imageCacheHeight, NetworkImage(image, scale: imageScale)),
     super(key: key);