搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。