getImage static method
获取模拟图片.
Implementation
static String getImage(
int width, {
int? height, //图片高度
int? id, //具体图片 id,参考 https://picsum.photos/images
String? seed, //根据 seed 获取固定静态图片
bool isGray = false, //灰色图片
int? blur, //毛玻璃效果,数字越大越模糊
int? random, // 获取相同大小的随机图片,避免缓存
bool isJpg = false, // 是否为 jpg 后缀
bool isWebp = false, // 当 isJpg 为 false,用于确定是否 webp 后缀
}) {
const base = 'https://picsum.photos';
var url = '$base/$width';
if (seed != null) {
url = '$base/seed/$seed/$width';
}
if (id != null) {
url = '$base/id/$id/$width';
}
if (height != null) {
url += '/$height';
}
if (isJpg) {
url += '.jpg';
} else {
if (isWebp) {
url += '.webp';
}
}
if (isGray) {
url += '?grayscale';
}
if (blur != null) {
if (url.contains('?')) {
url += '&blur=$blur';
} else {
url += '?blur=$blur';
}
}
if (random != null) {
if (url.contains('?')) {
url += '&random=$random';
} else {
url += '?random=$random';
}
}
return url;
}