asWidget method

Widget asWidget({
  1. Key? key,
  2. Anchor anchor = Anchor.topLeft,
  3. double angle = 0,
})

Implementation

widget.Widget asWidget({
  widget.Key? key,
  Anchor anchor = Anchor.topLeft,
  double angle = 0,
}) {
  if (this is Future) {
    return widget.FutureBuilder<Sprite>(
      key: key,
      future: this as Future<Sprite>,
      builder: (context, data) {
        if (!data.hasData) return const widget.SizedBox.shrink();
        return widget.Container(
          constraints: widget.BoxConstraints(
            minWidth: data.data!.src.width,
            minHeight: data.data!.src.height,
          ),
          child: SpriteWidget(
            sprite: data.data!,
            anchor: anchor,
            angle: angle,
          ),
        );
      },
    );
  }

  return widget.Container(
    key: key,
    constraints: widget.BoxConstraints(
      minWidth: (this as Sprite).src.width,
      minHeight: (this as Sprite).src.height,
    ),
    child: SpriteWidget(
      sprite: this as Sprite,
      anchor: anchor,
      angle: angle,
    ),
  );
}