初始化
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import '../tools_base/cache/dio_file_service.dart';
|
||||
|
||||
/// 视频缓存
|
||||
class VideoCacheManager extends CacheManager {
|
||||
static const key = "videoCache";
|
||||
|
||||
static VideoCacheManager? _instance;
|
||||
|
||||
factory VideoCacheManager() {
|
||||
_instance ??= VideoCacheManager._(fileService: DioFileService());
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
VideoCacheManager._({required FileService fileService})
|
||||
: super(Config(
|
||||
key,
|
||||
stalePeriod: const Duration(days: 100),
|
||||
maxNrOfCacheObjects: 200,
|
||||
fileService: fileService,
|
||||
));
|
||||
|
||||
/// 缓存存储路径
|
||||
Future<String?> getFilePath() async {
|
||||
final dir = await getCommonDir();
|
||||
return dir == null ? null : path.join(dir.path, key);
|
||||
}
|
||||
|
||||
/// 获取公用的dir目录
|
||||
static Future<Directory?> getCommonDir() {
|
||||
if (Platform.isIOS) return getTemporaryDirectory();
|
||||
if (Platform.isAndroid) return getExternalStorageDirectory();
|
||||
//桌面/其它平台用 app support 目录
|
||||
if (Platform.isFuchsia || Platform.isMacOS || Platform.isLinux || Platform.isWindows) {
|
||||
return getApplicationSupportDirectory();
|
||||
}
|
||||
return getExternalStorageDirectory();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user