asWidget method

Widget asWidget({
  1. Key? key,
  2. bool playing = true,
  3. Anchor anchor = Anchor.topLeft,
})

Implementation

widget.Widget asWidget({
  widget.Key? key,
  bool playing = true,
  Anchor anchor = Anchor.topLeft,
}) {
  if (this is Future) {
    return widget.FutureBuilder<SpriteAnimation>(
      key: key,
      future: this as Future<SpriteAnimation>,
      builder: (context, data) {
        if (!data.hasData) return const widget.SizedBox.shrink();
        return widget.Container(
          constraints: widget.BoxConstraints(
            minWidth: data.data!.frames.first.sprite.src.width,
            minHeight: data.data!.frames.first.sprite.src.height,
          ),
          child: SpriteAnimationWidget(
            animation: data.data!,
            animationTicker: data.data!.createTicker(),
            playing: playing,
            anchor: anchor,
          ),
        );
      },
    );
  }

  return widget.Container(
    key: key,
    constraints: widget.BoxConstraints(
      minWidth: (this as SpriteAnimation).frames.first.sprite.src.width,
      minHeight: (this as SpriteAnimation).frames.first.sprite.src.height,
    ),
    child: SpriteAnimationWidget(
      animation: this as SpriteAnimation,
      animationTicker: (this as SpriteAnimation).createTicker(),
      playing: playing,
      anchor: anchor,
    ),
  );
}