搜索插件、代码仓与 APP 分类

插件详情v3.0.1

optimized_cached_image

一个用于从网络加载图像、根据容器大小调整尺寸并在内存敏感的情况下进行缓存的库。

近 30 天下载
355
喜欢数
114
Pub 分数
60

安装插件

flutter pub add optimized_cached_image

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

OptimizedCachedImage 是一个 Flutter 包,旨在高效地加载、调整大小和缓存网络图像,同时最大限度地减少内存使用。它会自动调整图像大小以匹配容器尺寸,从而减少不必要的内存消耗。该库通过利用缓存机制和优化资源处理,确保流畅的性能。适用于频繁加载图像的应用程序,它在速度和效率之间取得平衡,而不会影响用户体验。

适合场景

  • 从URL加载动态图像
  • 调整图像大小以适应容器尺寸
  • 缓存图像以减少网络请求
  • 减少图像密集型应用中的内存占用
  • 通过高效的图像处理提升应用性能

主要特点

  • 自动图像调整大小
  • 内存高效的缓存
  • 网络图像加载
  • 容器感知的缩放
  • 低内存开销

适合对象

  • 图像流量高的应用
  • 性能关键的UI
  • 内存有限的移动应用
  • 图像画廊和动态
  • 电子商务或社交媒体应用

使用建议

  • 初始加载需要互联网连接
  • 可能需要为自定义缓存策略进行配置
  • 有限的平台特定优化
  • 不适用于静态本地图片
  • 依赖外部网络的可靠性

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Optimized Cached Image

pub package

❌❌ Important Update ❌❌

This library is no longer being maintained. When I started this library, it was meant to add memory performant extensions which could not be directly added into the parent library. Since then a lot has changed, the parent library has incorporated similar changes, perhaps with the exception of a trivial LayoutBuilder that auto detects image sizes. I feel like this is a good time to deprecate this library in favour of the parent.

Description

A flutter library for loading images from network, resizing and caching them for memory sensitivity. This resizes and stores the images in cache based on parent container constraints and hence loads images of lower size into memory. This is heavily inspired by cached_network_image library.

This library exposes two classes for loading images

  • OptimizedCacheImage which is a 1:1 mapping of CachedNetworkImage.
  • OptimizedCacheImageProvider which is a mapping of CachedNetworkImageProvider.

How to use

The OptimizedCacheImage can be used directly or through the ImageProvider. Both the OptimizedCacheImage as OptimizedCacheImageProvider have minimal support for web. It currently doesn't include caching.

With a placeholder:

OptimizedCacheImage(
        imageUrl: "http://via.placeholder.com/350x150",
        placeholder: (context, url) => CircularProgressIndicator(),
        errorWidget: (context, url, error) => Icon(Icons.error),
     ),

Or with a progress indicator:

OptimizedCacheImage(
       imageUrl: "http://via.placeholder.com/350x150",
       progressIndicatorBuilder: (context, url, downloadProgress) =>
               CircularProgressIndicator(value: downloadProgress.progress),
       errorWidget: (context, url, error) => Icon(Icons.error),
    ),
Image(image: OptimizedCacheImageProvider(url))

When you want to have both the placeholder functionality and want to get the imageprovider to use in another widget you can provide an imageBuilder:

OptimizedCacheImage(
  imageUrl: "http://via.placeholder.com/200x150",
  imageBuilder: (context, imageProvider) => Container(
    decoration: BoxDecoration(
      image: DecorationImage(
          image: imageProvider,
          fit: BoxFit.cover,
          colorFilter:
              ColorFilter.mode(Colors.red, BlendMode.colorBurn)),
    ),
  ),
  placeholder: (context, url) => CircularProgressIndicator(),
  errorWidget: (context, url, error) => Icon(Icons.error),
),

Handling Gifs

OCI uses Flutter Image Compress as the compression library, while being memory efficient this library doesn't provide out of box support for gifs, however it does allow compressing to webp. Hence all gifs are compressed to webp format beginning 2.0.2-alpha.

How it works

The optimized cached network images stores and retrieves files using the flutter_cache_manager.

FAQ

My app crashes when the image loading failed. (I know, this is not really a question.)

Does it really crash though? The debugger might pause, as the Dart VM doesn't recognize it as a caught exception; the console might print errors; even your crash reporting tool might report it (I know, that really sucks). However, does it really crash? Probably everything is just running fine. If you really get an app crashes you are fine to report an issue, but do that with a small example so we can reproduce that crash.

所属分类

依赖

依赖清单 11 项

源码仓库

使用此插件的项目

暂无相关数据。