31 lines
912 B
Dart
31 lines
912 B
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:common_utils/common_utils.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
class ImageUtils {
|
|
static ImageProvider getAssetImage(String name,
|
|
{ImageFormat format = ImageFormat.png}) {
|
|
return AssetImage(getImgPath(name, format: format));
|
|
}
|
|
|
|
static String getImgPath(String name,
|
|
{ImageFormat format = ImageFormat.png}) {
|
|
return 'assets/images/$name.${format.value}';
|
|
}
|
|
|
|
static ImageProvider getImageProvider(String? imageUrl,
|
|
{String holderImg = 'none'}) {
|
|
if (TextUtil.isEmpty(imageUrl)) {
|
|
return AssetImage(getImgPath(holderImg));
|
|
}
|
|
return CachedNetworkImageProvider(imageUrl!);
|
|
}
|
|
}
|
|
|
|
enum ImageFormat { png, jpg, gif, webp }
|
|
|
|
extension ImageFormatExtension on ImageFormat {
|
|
String get value => ['png', 'jpg', 'gif', 'webp'][index];
|
|
}
|