Files
flutter-todos/lib/config/custom_image_cache_manager.dart
2019-07-26 17:20:51 +08:00

36 lines
1.0 KiB
Dart

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<String> getFilePath() async {
var directory = await getTemporaryDirectory();
return p.join(directory.path, key);
}
static Future<FileFetcherResponse> _customHttpGetter(String url, {Map<String, String> headers}) async {
// Do things with headers, the url or whatever.
return HttpFileFetcherResponse(await http.get(url, headers: headers));
}
}