搜尋分類、套件與程式碼儲存庫

套件詳情v2.0.0

cached_network_svg_image

一個用於快取 SVG 圖像的 Flutter 套件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2.6萬
喜歡數
58
Pub 分數
120

安裝套件

flutter pub add cached_network_svg_image

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個專為從網路高效載入與快取 SVG 圖像設計的 Flutter 套件。它透過處理網路請求、快取與繪製,簡化了在 Flutter 應用中顯示可縮放向量圖形的過程,僅需最少的樣板程式碼。此套件支援 Android、iOS、Web、macOS、Windows 與 Linux 等多個平台,確保跨裝置行為一致。透過本機快取減少重複下載,進而提升效能並加快圖像載入速度。

適用情境

  • 從URL顯示可縮放的圖示
  • 快取遠端 SVG 資產以供離線使用
  • 透過快取向量圖形改善應用程式效能
  • 在跨平台 Flutter 應用中載入 SVG
  • 減少重複圖像加載的頻寬使用

主要特色

  • 自動緩存已下載的 SVG
  • 支援所有主要的 Flutter 平台
  • 高效記憶體和磁碟使用
  • 與現有 Flutter 程式碼的簡單整合
  • 內建錯誤處理和重試邏輯

適合對象

  • 需要頻繁加載SVG圖像的應用
  • 尋求優化圖像性能的開發者
  • 跨平台專案使用向量圖形
  • 面向離線功能的應用程式
  • 優先考慮乾淨、可重用的圖像組件的團隊

使用建議

  • 初始下載需要互聯網連接
  • 快取管理可能需要手動清除
  • 大型 SVG 檔案可能會影響初始載入時間
  • SVG 渲染選項的自訂有限
  • 取決於底層SVG解析庫的穩定性

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Cached Network SVG Image

cached_network_svg_image is a Flutter package that allows you to easily load and cache SVG images from the network. It provides a simple and efficient way to display SVG images with caching, placeholders, and error handling. 🌐🖼️ Now supports Web! 🌍

Features ✨

  • Load SVG images from the network. 🌍
  • Cache images for offline use. 📦
  • Display a placeholder while the image is loading. ⏳
  • Show an error widget if the image fails to load. ❌
  • Customize the fade-in duration for the image. ⏱️

Installation 🛠️

Add the following to your pubspec.yaml file:

dependencies:
  cached_network_svg_image: any

Then, run flutter pub get to install the package. 🚀

Usage 📖

Import the package in your Dart file:

import 'package:cached_network_svg_image/cached_network_svg_image.dart';

Use the CachedNetworkSVGImage widget to display an SVG image from the network:

CachedNetworkSVGImage(
    imageUrl: 'https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg',
    placeholder: const CircularProgressIndicator(color: Colors.green),
    errorWidget: const Icon(Icons.error, color: Colors.red),
    width: 250.0,
    height: 250.0,
    fadeDuration: const Duration(milliseconds: 500),
),
Parameters 📋
  • imageUrl: The URL of the SVG image. 🌐
  • cacheKey: A custom cache key to use for the image. 🔑
  • placeholder: A widget to display while the image is loading. ⏳
  • errorWidget: A widget to display if the image fails to load. ❌
  • width: The width of the image. 📏
  • height: The height of the image. 📏
  • fadeDuration: The duration of the fade-in animation when the image loads. ⏱️
  • headers: A map of headers to pass with the network request. 🗂️
  • cacheManager: A custom cache manager to use for caching the image, Default is DefaultCacheManager(). 📦
  • fit: How the image should be inscribed into the space allocated for it. 🔲
  • alignment: How the image should be aligned within its bounds. 📐
  • matchTextDirection: Whether to paint the image in the direction of the TextDirection. ↔️
  • allowDrawingOutsideViewBox: Whether to allow the image to draw outside its view box. 📏
  • color: The color to apply to the image. 🎨
  • colorBlendMode: The blend mode to apply to the image color. 🎨
  • semanticsLabel: A description of the image for accessibility tools. 🏷️
  • excludeFromSemantics: Whether the image should be excluded from semantics. 🚫
  • colorFilter: A color filter to apply to the image. 🎨
  • placeholderBuilder: A builder function to create the placeholder widget. 🛠️
  • theme: The theme to apply to the image. 🎨
Functions 🔧
  • preCache: A function to pre-cache the image. 📦
  • clearCacheForUrl: A function to clear the cache for a specific URL. 🗑️
  • clearCache: A function to clear the entire cache. 🗑️

Example 💡

Here is a complete example of how to use the cached_network_svg_image package:

import 'package:flutter/material.dart';
import 'package:cached_network_svg_image/cached_network_svg_image.dart';

void main() {
    runApp(MyApp());
}

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return MaterialApp(
            home: Scaffold(
                appBar: AppBar(
                    title: Text('Cached Network SVG Image Example'),
                ),
                body: Center(
                    child: CachedNetworkSVGImage(
                        imageUrl: 'https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg',
                        placeholder: const CircularProgressIndicator(color: Colors.green),
                        errorWidget: const Icon(Icons.error, color: Colors.red),
                        width: 250.0,
                        height: 250.0,
                        fadeDuration: const Duration(milliseconds: 500),
                    ),
                ),
            ),
        );
    }
}

License 📄

This project is licensed under the MIT License. See the LICENSE file for more details.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案