简体   繁体   中英

Cached Network SVG Image

I want to display an SVG picture retrieved from network with the help of Flutter_SVG package and use the same picture in different pages with the Hero widget. But each time I use SvgPicture.network() widget, it loads the image again and again from network;

Page 1 & Page 2

 Hero(
     tag: 'randomTag',
     child: SvgPicture.network(url),
 ),

I have tried to combine Cached Network Image dependency with Flutter_SVG package but don't know how to use them as a widget together;

Hero(
  tag: 'randomTag',
  child: CachedNetworkImage(
    imageUrl: url,
    imageBuilder: (context, ImageProvider<Object> imageProvider) {
      // How to use ImageProvider<Object> with SvgPicture?
    }
  ),
),

svg_cached_network_image dependency is not an option since it is not compatible with other dependencies that I use.

Use flutter_cache_manager to save svg from internet

This line get svg from internet and save it to local, and next time you call it it will get from local

var file = await DefaultCacheManager().getSingleFile(url);

https://pub.dev/documentation/flutter_cache_manager/latest/flutter_cache_manager/BaseCacheManager/getSingleFile.html

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM