buildImage method

Widget? buildImage(
  1. BuildTree tree,
  2. ImageMetadata data
)

Builds image widget from an ImageMetadata.

Implementation

Widget? buildImage(BuildTree tree, ImageMetadata data) {
  final src = data.sources.isNotEmpty ? data.sources.first : null;
  if (src == null) {
    return null;
  }

  var built = buildImageWidget(tree, src);

  final title = data.title;
  if (built != null && title != null) {
    built = buildTooltip(tree, built, title);
  }

  if (built != null) {
    final height = src.height;
    final width = src.width;
    if (height != null && height > 0 && width != null && width > 0) {
      built = buildAspectRatio(tree, built, width / height);
    }
  }

  final onTapImage = _widget?.onTapImage;
  if (onTapImage != null && built != null) {
    final recognizer = buildGestureRecognizer(
      tree,
      onTap: () => onTapImage(data),
    );
    if (recognizer != null) {
      built = buildGestureDetector(tree, built, recognizer);
    }
  }

  return built;
}