buildImageWidget method Null safety

Widget? buildImageWidget(
  1. BuildMetadata meta,
  2. ImageSource src
)

Builds Image.

Implementation

Widget? buildImageWidget(BuildMetadata meta, ImageSource src) {
  final url = src.url;

  ImageProvider? provider;
  if (url.startsWith('asset:')) {
    provider = imageProviderFromAsset(url);
  } else if (url.startsWith('data:image/')) {
    provider = imageProviderFromDataUri(url);
  } else if (url.startsWith('file:')) {
    provider = imageProviderFromFileUri(url);
  } else {
    provider = imageProviderFromNetwork(url);
  }
  if (provider == null) {
    return null;
  }

  final image = src.image;
  final semanticLabel = image?.alt ?? image?.title;
  return Image(
    errorBuilder: (context, error, _) =>
        onErrorBuilder(context, meta, error, src) ?? widget0,
    loadingBuilder: (context, child, loadingProgress) =>
        loadingProgress == null
            ? child
            : onLoadingBuilder(
                  context,
                  meta,
                  loadingProgress.expectedTotalBytes != null &&
                          loadingProgress.expectedTotalBytes! > 0
                      ? loadingProgress.cumulativeBytesLoaded /
                          loadingProgress.expectedTotalBytes!
                      : null,
                  src,
                ) ??
                child,
    excludeFromSemantics: semanticLabel == null,
    fit: BoxFit.fill,
    image: provider,
    semanticLabel: semanticLabel,
  );
}