import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import 'package:path_provider/path_provider.dart'; import 'package:http/http.dart' as http; import 'package:path/path.dart' as p; //图片缓存管理类,目前没有用到 class CustomCacheManager extends BaseCacheManager { static const key = "customCache"; static CustomCacheManager _instance; factory CustomCacheManager() { if (_instance == null) { _instance = new CustomCacheManager._(); } return _instance; } CustomCacheManager._() : super(key, maxAgeCacheObject: Duration(hours: 12), maxNrOfCacheObjects: 1, fileFetcher: _customHttpGetter); Future getFilePath() async { var directory = await getTemporaryDirectory(); return p.join(directory.path, key); } static Future _customHttpGetter(String url, {Map headers}) async { // Do things with headers, the url or whatever. return HttpFileFetcherResponse(await http.get(url, headers: headers)); } }