buildImage method Null safety

Widget? buildImage(
  1. BuildMetadata meta,
  2. ImageMetadata data
)

Builds image widget from an ImageMetadata.

Implementation

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

  var built = buildImageWidget(meta, src);

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

  if (built != null &&
      src.height?.isNegative == false &&
      src.width?.isNegative == false &&
      src.height != 0) {
    built = buildAspectRatio(meta, built, src.width! / src.height!);
  }

  if (_widget?.onTapImage != null && built != null) {
    built = buildGestureDetector(
      meta,
      built,
      () => _widget?.onTapImage?.call(data),
    );
  }

  return built;
}