Pub上面关于Image的插件挺多的,但是为啥我还是想要做一个呢,主要是pub上面感觉不够自定义化。
extended_image跟官方的用法一模一样,但是增加了许多实用的功能。
缓存网络图片
ExtendedNetworkImageProvider除了缓存的功能还提供了重试,超时等功能
ExtendedNetworkImageProvider(this.url,
{this.scale = 1.0,
this.headers,
this.cache: false,
this.retries = 3,
this.timeLimit,
this.timeRetry = const Duration(milliseconds: 100)})
: assert(url != null),
assert(scale != null);
///time Limit to request image
final Duration timeLimit;
///the time to retry to request
final int retries;
///the time duration to retry to request
final Duration timeRetry;
///whether cache image to local
final bool cache;
/// The URL from which the image will be fetched.
final String url;
/// The scale to place in the [ImageInfo] object of the image.
final double scale;
/// The HTTP headers that will be used with [HttpClient.get] to fetch image from network.
final Map<String, String> headers;
或者你也可以这样用
ExtendedImage.network(
url,
cache: true,
),
圆角,边框,圆形
ExtendedImage.network(
url,
width: ScreenUtil.instance.setWidth(400),
height: ScreenUtil.instance.setWidth(400),
fit: BoxFit.fill,
cache: true,
border: Border.all(color: Colors.red, width: 1.0),
shape: boxShape,
borderRadius: BorderRadius.all(Radius.circular(30.0)),
),
清除本地缓存,清除内存缓存,保存网络图片到相册
清除本地缓存,你可以选择清楚全部,也可以给一个时间(清除比如7天之前的)
// Clear the disk cache directory