imageUrl method

  1. @override
Uri imageUrl(
  1. String imageRefId, {
  2. ImageOptions? options,
})
override

Builds a URL for an image asset.

Implementation

@override
Uri imageUrl(String imageRefId, {ImageOptions? options}) {
  _assertValidImageOptions(options);

  final fileName = SanityUrlBuilder.imageFileName(imageRefId);

  final path = '${config.projectId}/${config.dataset}/$fileName';

  final params = options == null
      ? ''
      : [
          if (options.width != null) 'w=${options.width}',
          if (options.height != null) 'h=${options.height}',
          if (options.devicePixelRatio != null)
            'dpr=${options.devicePixelRatio}',
          if (options.format != null) 'fm=${options.format}',
          if (options.quality != null)
            'q=${max(0, min(options.quality!, 100))}',
        ].join('&');

  final query = params.isEmpty ? '' : '?$params';
  return Uri.parse('https://cdn.sanity.io/images/$path$query');
}