flutter 清除图片缓存

作者: wethereornot | 来源:发表于2019-01-29 16:02 被阅读558次
    ///实现Flutter框架的图像缓存的单例。
    The singleton that implements the Flutter framework's image cache.
    
    ///该缓存由ImageProvider内部使用,通常不应该直接访问。
    The cache is used internally by [ImageProvider](https://docs.flutter.io/flutter/painting/ImageProvider-class.html) and should generally not be accessed directly.
    
    ///图像缓存是在启动时由绘图绑定的绘图绑定创建的。createImageCache方法。
    The image cache is created during startup by the  PaintingBinding's PaintingBinding.createImageCache  method.
    
    

    介绍其中几个重要的方法

    1.获取ImageCache 缓存对象
     ImageCache get imageCache => PaintingBinding.instance.imageCache;
    2.设置缓存图片的个数(根据情况自己设置,default = 1000)
      imageCache.maximumSize = 1000;
    3.获取缓存图片个数
     int num = imageCache.currentSize;
    4.设置缓存大小(根据情况自己设置,default = 50M)
     imageCache.maximumSizeBytes=50<<20;
    5.获取图片缓存大小(单位是byte,需自行转换到 M)
    int byte=imageCache.currentSizeBytes
    6.清除图片缓存
     imageCache.clear();
    

    自行查看flutter文档介绍

    相关文章

      网友评论

        本文标题:flutter 清除图片缓存

        本文链接:https://www.haomeiwen.com/subject/mcmxsqtx.html