getFinalStyle method

  1. @override
AntdImageStyle getFinalStyle(
  1. BuildContext context,
  2. AntdImageStyle style,
  3. AntdMapToken token
)
override

Implementation

@override
AntdImageStyle getFinalStyle(
    BuildContext context, AntdImageStyle style, AntdMapToken token) {
  var size = getSize(style);

  if (style.errorBuild == null) {
    style = style.copyWith(errorBuild: (context, error, stackTrace) {
      return AntdIcon(
        icon: AntdIcons.pictureWrong,
        style: AntdIconStyle(
            color: token.colorText.quaternary,
            bodyStyle: style.bodyStyle?.copyFrom(AntdBoxStyle(
                alignment: Alignment.center,
                height: size.height,
                width: size.width,
                color: token.colorFill.tertiary))),
      );
    });
  }
  if (style.loadBuild == null) {
    style = style.copyWith(loadBuild: (context, child, loadingProgress) {
      if (loadingProgress == null) return child;

      double calculateLoadingSize(double? height, double? width) {
        const minSize = 0.0;
        const maxSize = 24.0;
        const ratio = 0.4;

        final validHeight = height ?? double.infinity;
        final validWidth = width ?? double.infinity;
        final containerSize = min(validHeight, validWidth);

        if (containerSize.isInfinite) return minSize;

        return (containerSize * ratio).clamp(minSize, maxSize);
      }

      final loadingSize = calculateLoadingSize(size.height, size.width);

      return AntdBox(
        style: style.bodyStyle?.copyFrom(AntdBoxStyle(
          height: size.height,
          width: size.width,
          color: token.colorBgLayout,
        )),
        child: Center(
          child: AntdLoading(
            circular: true,
            style: AntdLoadingStyle(size: loadingSize),
            spinning: true,
          ),
        ),
      );
    });
  }
  return style;
}