build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Implementation

@override
Widget build(context) {
  Widget result = child;

  /// library
  if (toPhotoData.data != null) {
    result = Icon(
      toPhotoData.data,
      color: color,
      size: layout().shortestSide,
    );
  }

  /// asset
  if (toPhotoData.path != null) {
    result = Image.asset(
      toPhotoData.path!,
      fit: boxFit,
      alignment: layout().alignment ?? Alignment.center,
      color: color,
      colorBlendMode: blendMode,
      width: layout().width,
      height: layout().height,
    );
  }

  /// network
  if (toPhotoData.src != null) {
    Widget loader(ImageChunkEvent chunk) {
      final loadValue =
          (chunk.expectedTotalBytes != null ? chunk.cumulativeBytesLoaded / chunk.expectedTotalBytes! : null);
      return Center(
        child: Container(
          height: 36,
          width: 36,
          padding: const EdgeInsets.all(8.0),
          child: CircularProgressIndicator(
            strokeWidth: 2,
            backgroundColor: palette.background,
            value: loadValue,
          ),
        ),
      );
    }

    Widget error([StackTrace? trace]) {
      return Center(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: $icon.picture(Picture.error),
        ),
      );
    }

    result = Image.network(
      toPhotoData.src!,
      color: color,
      fit: boxFit,
      alignment: layout().alignment ?? Alignment.center,
      colorBlendMode: blendMode,
      height: layout().height,
      width: layout().width,
      errorBuilder: (c, o, s) => error(s),
      loadingBuilder: (c, child, chunk) => chunk == null ? child : loader(chunk),
    );
  }
  return inkwell().wrap([layout().wrap([result,]), ...children]);
}