1234567891011121314151617181920212223242526272829 |
- 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) {
- return AssetImage(getImgPath(name));
- }
- static String getImgPath(String name) {
- if(name.startsWith("assets/images/")){
- name = name.substring(14);
- }
- if (name.startsWith('/')) {
- name = name.substring(1);
- }
- return 'assets/images/$name';
- }
- static ImageProvider getImageProvider(String? imageUrl, {String holderImg = 'none'}) {
- if (TextUtil.isEmpty(imageUrl)) {
- return AssetImage(getImgPath(holderImg));
- }
- return CachedNetworkImageProvider(imageUrl!);
- }
- }
|