SpriteWidget.asset constructor

SpriteWidget.asset({
  1. required String path,
  2. Images? images,
  3. Anchor anchor = Anchor.topLeft,
  4. double angle = 0,
  5. Vector2? srcPosition,
  6. Vector2? srcSize,
  7. WidgetBuilder? errorBuilder,
  8. WidgetBuilder? loadingBuilder,
  9. Paint? paint,
  10. bool rasterize = false,
  11. Size? size,
  12. String? package,
  13. Key? key,
})

Load the image from the asset path and renders it as a widget.

It will use the loadingBuilder while the image from path is loading. To render without loading, or when you want to have a gapless playback when the path value changes, consider loading the image beforehand and direct pass it to the default constructor.

The path is the full path of the asset, as declared in the pubspec.yaml, for example assets/images/player.png.

Implementation

SpriteWidget.asset({
  required String path,
  Images? images,
  this.anchor = Anchor.topLeft,
  this.angle = 0,
  Vector2? srcPosition,
  Vector2? srcSize,
  this.errorBuilder,
  this.loadingBuilder,
  this.paint,
  this.rasterize = false,
  this.size,
  String? package,
  super.key,
}) : _spriteFuture = Sprite.load(
       path,
       srcSize: srcSize,
       srcPosition: srcPosition,
       images: images,
       package: package,
     );