imageProvider static method
Returns an ImageProvider from the specifed map.
The source key of the specified map is controlling. It must be a string.
If its value is one of the keys in imageProviderDecoders, then the
relevant decoder is invoked and its return value is used (even if it is
null).
Otherwise, if the source key gives an absolute URL (one with a scheme),
then a NetworkImage with that URL is returned. Its scale is given by the
scale key (double, defaults to 1.0).
Otherwise, if the source key gives a relative URL (i.e. it can be parsed
as a URL and has no scheme), an AssetImage with the name given by the
source key is returned.
Otherwise, if there is no source key in the map, or if that cannot be
parsed as a URL (absolute or relative), null is returned.
Implementation
static Map<String, dynamic>? imageProvider(ImageProvider? provider) {
if (provider == null) {
return null;
}
if (provider is ResizeImage) {
provider = provider.imageProvider;
}
if (provider is NetworkImage) {
return <String, dynamic>{'source': provider.url, 'scale': provider.scale};
} else if (provider is AssetImage) {
return <String, dynamic>{'source': provider.assetName};
}
final encoder = imageProviderEncoders[provider.runtimeType];
if (encoder != null) {
return encoder(provider);
}
return null;
}