パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v4.0.6

cached_network_image

ネットワーク画像の読み込みとキャッシュを行うFlutterライブラリ。プレースホルダーやエラーウィジェットとも併用可能。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
366万
いいね数
6990
Pub ポイント
150

パッケージをインストール

flutter pub add cached_network_image

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

ネットワーク画像を効率的に読み込み、キャッシュするためのFlutterパッケージで、プレースホルダーとエラーウィジェットのサポートを備えています。画像をローカルに保存することで、重複ダウンロードを減らし、アプリのパフォーマンスを向上させ、帯域幅の使用量を削減します。ソーシャルメディアフィードや製品カタログなど、リモートソースから多数の画像を表示するアプリに最適です。ライブラリは画像の読み込みを非同期で処理し、読み込み状態や失敗時のカスタマイズ可能なUIを提供します。

用途

  • アプリケーションで動的画像コンテンツを表示する
  • リモートサーバーから画像を効率的に読み込む
  • 読み込み中にプレースホルダ画像を表示する
  • 画像の読み込み失敗を適切に処理する
  • ローカルキャッシングによるデータ使用量の削減
  • 画像が多く含まれるユーザーインターフェースの構築

主な機能

  • 自動画像キャッシュ
  • カスタマイズ可能なプレースホルダーやエラーウィジェット
  • すべての主要プラットフォームに対応
  • 効率的なメモリとディスク管理
  • 非同期画像の読み込み
  • 設定可能なキャッシュサイズと期間

適している対象

  • 頻繁な画像取得を行うアプリ
  • パフォーマンスとUXを重視する開発者
  • オフライン画像アクセスを必要とするプロジェクト
  • ソーシャルメディアおよび電子商取引アプリケーション
  • 複数のプラットフォームをターゲットにするアプリ

注意事項

  • ストレージの問題を回避するためには適切なキャッシュ管理が必要です
  • 大規模な画像セットに対して調整が必要になる場合があります
  • プラットフォーム固有の動作はわずかに異なる場合があります
  • 初期設定にはキャッシュ戦略の理解が必要です
  • 非常に小さな静的画像コレクションには適していません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Cached network image

pub package codecov Build Status

A flutter library to show images from the internet and keep them in the cache directory.

Sponsors


Try the Flutter Chat Tutorial 💬

How to use

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

With a placeholder:

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

Or with a progress indicator:

CachedNetworkImage(
       imageUrl: "http://via.placeholder.com/350x150",
       progressIndicatorBuilder: (context, url, downloadProgress) => 
               CircularProgressIndicator(value: downloadProgress.progress),
       errorWidget: (context, url, error) => Icon(Icons.error),
    ),
Image(image: CachedNetworkImageProvider(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:

CachedNetworkImage(
  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),
),

How it works

The 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.

See for example this or this answer on previous posted issues.

カテゴリー

依存関係

依存関係一覧 5 件

ソースリポジトリ

このパッケージを使用しているプロジェクト