render method

  1. @override
Widget render(
  1. NudgeImage node,
  2. BuildContext context
)
override

Implementation

@override
Widget render(NudgeImage node, BuildContext context) {
  final url = VariableScopeProvider.of(context).resolve(node.url);
  if (url.isEmpty) {
    return _placeholder(node);
  }
  // Placeholder shown while the image downloads (a blurhash auto-computed by
  // the dashboard); null builder when the payload carried none.
  final placeholder =
      imagePlaceholderBuilder(node.placeholder, fit: node.fit);
  // Aspect ratio (when set) drives the height; otherwise use the box's fixed
  // height, then natural size.
  final Widget image;
  if (node.aspectRatio > 0) {
    image = AspectRatio(
      aspectRatio: node.aspectRatio,
      child: CachedNetworkImage(
        imageUrl: url,
        fit: node.fit,
        placeholder: placeholder,
        errorWidget: (_, __, ___) => _placeholder(node),
      ),
    );
  } else {
    image = CachedNetworkImage(
      imageUrl: url,
      fit: node.fit,
      width: node.box.fillWidth ? double.infinity : null,
      height: node.box.fixedHeight,
      placeholder: placeholder,
      errorWidget: (_, __, ___) => _placeholder(node),
    );
  }
  // Clip the image to the box's corners at the source — like the carousel and
  // lottie renderers — so rounded corners hold even with a BoxFit.cover image.
  // Inset by the border width so the rounded image sits inside the border the
  // decorator draws, instead of bleeding under it.
  if (node.box.borderRadius > 0) {
    final inner = (node.box.borderRadius - node.box.borderWidth)
        .clamp(0.0, double.infinity);
    return ClipRRect(
      borderRadius: BorderRadius.circular(inner.toDouble()),
      child: image,
    );
  }
  return image;
}