Buscar categorias, pacotes e repositórios

Detalhes do pacotev2.0.0

cached_network_svg_image

Um pacote Flutter para armazenar em cache imagens SVG.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
25,7 mil
Curtidas
58
Pontos Pub
120

Instalar pacote

flutter pub add cached_network_svg_image

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

Um pacote Flutter projetado para carregar e armazenar em cache imagens SVG da web de forma eficiente. Ele simplifica a exibição de gráficos vetoriais escaláveis em aplicativos Flutter, gerenciando solicitações de rede, cache e renderização com mínimo boilerplate. O pacote suporta múltiplas plataformas, incluindo Android, iOS, Web, macOS, Windows e Linux, garantindo comportamento consistente entre dispositivos. Melhora o desempenho reduzindo downloads redundantes e acelerando os tempos de carregamento de imagens por meio do cache local.

Casos de uso

  • Exibindo ícones escaláveis de URLs
  • Armazenando em cache ativos SVG remotos para uso offline
  • Melhorando o desempenho do aplicativo com gráficos vetoriais em cache
  • Carregando SVGs em aplicativos Flutter multiplataforma
  • Reduzindo o uso de largura de banda para carregamentos repetidos de imagens

Principais recursos

  • Cache automático de SVGs baixados
  • Suporte para todas as principais plataformas do Flutter
  • Uso eficiente de memória e disco
  • Integração simples com código Flutter existente
  • Tratamento de erros e lógica de repetição embutidos

Indicado para

  • Aplicativos que exigem carregamento frequente de imagens SVG
  • Desenvolvedores procurando desempenho otimizado de imagem
  • Projetos multiplataforma usando gráficos vetoriais
  • Aplicações direcionadas à funcionalidade offline
  • Equipes que priorizam componentes de imagem limpos e reutilizáveis

Considerações

  • Requer acesso à internet para o download inicial
  • A gestão de cache pode precisar de limpeza manual
  • Arquivos SVG grandes podem afetar o tempo de carregamento inicial
  • Personalização limitada para opções de renderização SVG
  • Depende da estabilidade da biblioteca de análise SVG subjacente

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

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.

Categorias

Dependências

Lista de dependências 2 itens

Repositório-fonte

Projetos que usam este pacote