mirror of
https://github.com/asjqkkkk/flutter-todos.git
synced 2025-08-06 14:19:24 +08:00
36 lines
1.0 KiB
Dart
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(days: 1),
|
|
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));
|
|
}
|
|
} |