cached_network_svg_image 1.2.0
cached_network_svg_image: ^1.2.0 copied to clipboard
A Flutter package for caching SVG images.
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. ππΌοΈ
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 isDefaultCacheManager()
. π¦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.