Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

add cache manager

Prediditfa236d635600
diff --git a/lib/pages/about/about_page.dart b/lib/pages/about/about_page.dart
index b70cb10c..e6d10741 100644
--- a/lib/pages/about/about_page.dart
+++ b/lib/pages/about/about_page.dart
@@ -1,3 +1,4 @@
+import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/pages/my/my_controller.dart';
@@ -7,7 +8,10 @@ import 'package:url_launcher/url_launcher.dart';
import 'package:kazumi/bean/appbar/sys_app_bar.dart';
import 'package:kazumi/pages/menu/menu.dart';
import 'package:kazumi/pages/menu/side_menu.dart';
+import 'package:path_provider/path_provider.dart';
+import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:provider/provider.dart';
+import 'package:flutter_cache_manager/flutter_cache_manager.dart';
class AboutPage extends StatefulWidget {
const AboutPage({super.key});
@@ -21,6 +25,7 @@ class _AboutPageState extends State<AboutPage> {
late dynamic defaultDanmakuArea;
late dynamic defaultThemeMode;
late dynamic defaultThemeColor;
+ double _cacheSizeMB = -1;
final MyController myController = Modular.get<MyController>();
@override
@@ -33,12 +38,91 @@ class _AboutPageState extends State<AboutPage> {
navigationBarState =
Provider.of<SideNavigationBarState>(context, listen: false);
}
+ _getCacheSize();
}
void onBackPressed(BuildContext context) {
navigationBarState.showNavigate();
}
+ Future<void> _getCacheSize() async {
+ Directory tempDir = await getTemporaryDirectory();
+ Directory cacheDir = Directory('${tempDir.path}/libCachedImageData');
+
+ if (await cacheDir.exists()) {
+ int totalSizeBytes = await _getTotalSizeOfFilesInDir(cacheDir);
+ double totalSizeMB = (totalSizeBytes / (1024 * 1024));
+
+ if (mounted) {
+ setState(() {
+ _cacheSizeMB = totalSizeMB;
+ });
+ }
+ } else {
+ if (mounted) {
+ setState(() {
+ _cacheSizeMB = 0.0;
+ });
+ }
+ }
+ }
+
+ Future<int> _getTotalSizeOfFilesInDir(final Directory directory) async {
+ final List<FileSystemEntity> children = directory.listSync();
+ int total = 0;
+
+ try {
+ for (final FileSystemEntity child in children) {
+ if (child is File) {
+ final int length = await child.length();
+ total += length;
+ } else if (child is Directory) {
+ total += await _getTotalSizeOfFilesInDir(child);
+ }
+ }
+ } catch (_) {}
+ return total;
+ }
+
+ Future<void> _clearCache() async {
+ final cacheManager = DefaultCacheManager();
+ await cacheManager.emptyCache();
+ _getCacheSize();
+ }
+
+ void _showCacheDialog() {
+ SmartDialog.show(
+ useAnimation: false,
+ builder: (context) {
+ return AlertDialog(
+ title: const Text('缓存管理'),
+ content: const Text('缓存为番剧封面, 清除后加载时需要重新下载,确认要清除缓存吗?'),
+ actions: [
+ TextButton(
+ onPressed: () {
+ SmartDialog.dismiss();
+ },
+ child: Text(
+ '取消',
+ style:
+ TextStyle(color: Theme.of(context).colorScheme.outline),
+ ),
+ ),
+ TextButton(
+ onPressed: () async {
+ try {
+ _clearCache();
+ } catch (_) {}
+ SmartDialog.dismiss();
+ },
+ child: const Text('确认'),
+ ),
+ ],
+ );
+ },
+ );
+ }
+
@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -77,6 +161,18 @@ class _AboutPageState extends State<AboutPage> {
.labelMedium!
.copyWith(color: Theme.of(context).colorScheme.outline)),
),
+ ListTile(
+ onTap: () {
+ _showCacheDialog();
+ },
+ dense: false,
+ title: const Text('清除缓存'),
+ trailing: _cacheSizeMB == -1 ? const Text('统计中...') :Text('${_cacheSizeMB.toStringAsFixed(2)}MB',
+ style: Theme.of(context)
+ .textTheme
+ .labelMedium!
+ .copyWith(color: Theme.of(context).colorScheme.outline)),
+ ),
ListTile(
onTap: () {
myController.checkUpdata();