From 16fa4677423b95dd829b087b6c0104c92afa6d87 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Tue, 19 Nov 2024 23:50:45 +0800 Subject: [PATCH 1/3] refactor: GlobalDataCache --- lib/common/widgets/network_img_layer.dart | 2 +- lib/http/member.dart | 8 +-- lib/main.dart | 2 +- lib/pages/dynamics/widgets/up_panel.dart | 2 +- lib/pages/main/view.dart | 2 +- lib/pages/member_archive/controller.dart | 5 +- lib/pages/member_article/controller.dart | 5 +- lib/pages/member_dynamics/controller.dart | 5 +- lib/pages/member_seasons/controller.dart | 2 +- lib/pages/search/controller.dart | 8 +-- lib/pages/setting/extra_setting.dart | 4 +- lib/pages/setting/pages/action_menu_set.dart | 2 +- lib/pages/setting/pages/play_gesture_set.dart | 4 +- lib/pages/setting/play_setting.dart | 2 +- lib/pages/setting/style_setting.dart | 2 +- lib/pages/video/detail/introduction/view.dart | 6 +-- .../detail/reply/widgets/reply_item.dart | 4 +- lib/pages/video/detail/widgets/ai_detail.dart | 2 +- lib/plugin/pl_player/controller.dart | 38 +++++++------- lib/plugin/pl_player/view.dart | 4 +- lib/utils/global_data_cache.dart | 52 +++++++++---------- lib/utils/login.dart | 2 +- 22 files changed, 79 insertions(+), 84 deletions(-) diff --git a/lib/common/widgets/network_img_layer.dart b/lib/common/widgets/network_img_layer.dart index 4980e2fc..b7b5de7e 100644 --- a/lib/common/widgets/network_img_layer.dart +++ b/lib/common/widgets/network_img_layer.dart @@ -48,7 +48,7 @@ class NetworkImgLayer extends StatelessWidget { Widget build(BuildContext context) { int defaultImgQuality = 10; try { - defaultImgQuality = GlobalDataCache().imgQuality; + defaultImgQuality = GlobalDataCache.imgQuality; } catch (_) {} if (src == '' || src == null) { diff --git a/lib/http/member.dart b/lib/http/member.dart index 66d0ff47..107a9379 100644 --- a/lib/http/member.dart +++ b/lib/http/member.dart @@ -26,7 +26,7 @@ class MemberHttp { }) async { String? wWebid; if ((await getWWebid(mid: mid))['status']) { - wWebid = GlobalDataCache().wWebid; + wWebid = GlobalDataCache.wWebid; } Map params = await WbiSign().makSign({ @@ -574,7 +574,7 @@ class MemberHttp { } static Future getWWebid({required int mid}) async { - String? wWebid = GlobalDataCache().wWebid; + String? wWebid = GlobalDataCache.wWebid; if (wWebid != null) { return {'status': true, 'data': wWebid}; } @@ -588,7 +588,7 @@ class MemberHttp { final content = match.group(1); String decodedString = Uri.decodeComponent(content!); Map map = jsonDecode(decodedString); - GlobalDataCache().wWebid = map['access_id']; + GlobalDataCache.wWebid = map['access_id']; return {'status': true, 'data': map['access_id']}; } else { return {'status': false, 'data': '请检查登录状态'}; @@ -605,7 +605,7 @@ class MemberHttp { }) async { String? wWebid; if ((await getWWebid(mid: mid))['status']) { - wWebid = GlobalDataCache().wWebid; + wWebid = GlobalDataCache.wWebid; } Map params = await WbiSign().makSign({ 'host_mid': mid, diff --git a/lib/main.dart b/lib/main.dart index 1ec86c8e..5a163f49 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -65,7 +65,7 @@ void main() async { } PiliSchame.init(); - await GlobalDataCache().initialize(); + await GlobalDataCache.initialize(); } class MyApp extends StatelessWidget { diff --git a/lib/pages/dynamics/widgets/up_panel.dart b/lib/pages/dynamics/widgets/up_panel.dart index d5d7958e..607b6af7 100644 --- a/lib/pages/dynamics/widgets/up_panel.dart +++ b/lib/pages/dynamics/widgets/up_panel.dart @@ -173,7 +173,7 @@ class _UpPanelState extends State { if (data.type == 'up') { EasyThrottle.throttle('follow', const Duration(milliseconds: 300), () { - if (GlobalDataCache().enableDynamicSwitch) { + if (GlobalDataCache.enableDynamicSwitch) { onClickUp(data, i); } else { onClickUpAni(data, i); diff --git a/lib/pages/main/view.dart b/lib/pages/main/view.dart index 01fae4bf..1c4dbf62 100644 --- a/lib/pages/main/view.dart +++ b/lib/pages/main/view.dart @@ -125,7 +125,7 @@ class _MainAppState extends State with SingleTickerProviderStateMixin { double sheetHeight = MediaQuery.sizeOf(context).height - MediaQuery.of(context).padding.top - MediaQuery.sizeOf(context).width * 9 / 16; - GlobalDataCache().sheetHeight = sheetHeight; + GlobalDataCache.sheetHeight = sheetHeight; localCache.put('sheetHeight', sheetHeight); localCache.put('statusBarHeight', statusBarHeight); diff --git a/lib/pages/member_archive/controller.dart b/lib/pages/member_archive/controller.dart index 61816ed5..3fdcbedc 100644 --- a/lib/pages/member_archive/controller.dart +++ b/lib/pages/member_archive/controller.dart @@ -28,9 +28,8 @@ class MemberArchiveController extends GetxController { super.onInit(); mid = int.parse(Get.parameters['mid']!); currentOrder.value = orderList.first; - ownerMid = GlobalDataCache().userInfo != null - ? GlobalDataCache().userInfo!.mid! - : -1; + ownerMid = + GlobalDataCache.userInfo != null ? GlobalDataCache.userInfo!.mid! : -1; isOwner.value = mid == -1 || mid == ownerMid; } diff --git a/lib/pages/member_article/controller.dart b/lib/pages/member_article/controller.dart index 9c67f679..542fbc4f 100644 --- a/lib/pages/member_article/controller.dart +++ b/lib/pages/member_article/controller.dart @@ -20,9 +20,8 @@ class MemberArticleController extends GetxController { void onInit() { super.onInit(); mid = int.parse(Get.parameters['mid']!); - ownerMid = GlobalDataCache().userInfo != null - ? GlobalDataCache().userInfo!.mid! - : -1; + ownerMid = + GlobalDataCache.userInfo != null ? GlobalDataCache.userInfo!.mid! : -1; isOwner.value = mid == -1 || mid == ownerMid; } diff --git a/lib/pages/member_dynamics/controller.dart b/lib/pages/member_dynamics/controller.dart index 8fdf55b7..be5b2454 100644 --- a/lib/pages/member_dynamics/controller.dart +++ b/lib/pages/member_dynamics/controller.dart @@ -18,9 +18,8 @@ class MemberDynamicsController extends GetxController { void onInit() { super.onInit(); mid = int.parse(Get.parameters['mid']!); - ownerMid = GlobalDataCache().userInfo != null - ? GlobalDataCache().userInfo!.mid! - : -1; + ownerMid = + GlobalDataCache.userInfo != null ? GlobalDataCache.userInfo!.mid! : -1; isOwner.value = mid == -1 || mid == ownerMid; } diff --git a/lib/pages/member_seasons/controller.dart b/lib/pages/member_seasons/controller.dart index 07532787..e3f2c409 100644 --- a/lib/pages/member_seasons/controller.dart +++ b/lib/pages/member_seasons/controller.dart @@ -59,7 +59,7 @@ class MemberSeasonsController extends GetxController { mid: mid, seriesId: seriesId!, pn: pn, - currentMid: GlobalDataCache().userInfo?.mid ?? -1, + currentMid: GlobalDataCache.userInfo?.mid ?? -1, ); if (res['status']) { seasonsList.addAll(res['data'].seriesList); diff --git a/lib/pages/search/controller.dart b/lib/pages/search/controller.dart index 2da2acff..8d24f167 100644 --- a/lib/pages/search/controller.dart +++ b/lib/pages/search/controller.dart @@ -43,10 +43,10 @@ class SSearchController extends GetxController { hintText = hint; } } - historyCacheList = GlobalDataCache().historyCacheList; + historyCacheList = GlobalDataCache.historyCacheList; historyList.value = historyCacheList; enableHotKey = setting.get(SettingBoxKey.enableHotKey, defaultValue: true); - enableSearchSuggest = GlobalDataCache().enableSearchSuggest; + enableSearchSuggest = GlobalDataCache.enableSearchSuggest; } void onChange(value) { @@ -128,7 +128,7 @@ class SSearchController extends GetxController { historyCacheList = []; historyList.refresh(); localCache.put('cacheList', []); - GlobalDataCache().historyCacheList = []; + GlobalDataCache.historyCacheList = []; SmartDialog.showToast('搜索历史已清空'); } @@ -139,7 +139,7 @@ class SSearchController extends GetxController { historyList.value = historyCacheList; historyList.refresh(); localCache.put('cacheList', historyCacheList); - GlobalDataCache().historyCacheList = historyCacheList; + GlobalDataCache.historyCacheList = historyCacheList; searchFocusNode.unfocus(); } } diff --git a/lib/pages/setting/extra_setting.dart b/lib/pages/setting/extra_setting.dart index 07cd585a..fdc62f13 100644 --- a/lib/pages/setting/extra_setting.dart +++ b/lib/pages/setting/extra_setting.dart @@ -146,7 +146,7 @@ class _ExtraSettingState extends State { setKey: SettingBoxKey.enableSearchSuggest, defaultVal: true, callFn: (val) { - GlobalDataCache().enableSearchSuggest = val; + GlobalDataCache.enableSearchSuggest = val; }, ), SetSwitchItem( @@ -181,7 +181,7 @@ class _ExtraSettingState extends State { setKey: SettingBoxKey.enableAutoExpand, defaultVal: false, callFn: (val) { - GlobalDataCache().enableAutoExpand = val; + GlobalDataCache.enableAutoExpand = val; }, ), const SetSwitchItem( diff --git a/lib/pages/setting/pages/action_menu_set.dart b/lib/pages/setting/pages/action_menu_set.dart index cbbd0e84..3b211bae 100644 --- a/lib/pages/setting/pages/action_menu_set.dart +++ b/lib/pages/setting/pages/action_menu_set.dart @@ -38,7 +38,7 @@ class _ActionMenuSetPageState extends State { .map((i) => (i['value'] as ActionType).value) .toList(); setting.put(SettingBoxKey.actionTypeSort, sortedTabbar); - GlobalDataCache().actionTypeSort = sortedTabbar; + GlobalDataCache.actionTypeSort = sortedTabbar; SmartDialog.showToast('操作成功'); } diff --git a/lib/pages/setting/pages/play_gesture_set.dart b/lib/pages/setting/pages/play_gesture_set.dart index bad115a5..dc11cd6f 100644 --- a/lib/pages/setting/pages/play_gesture_set.dart +++ b/lib/pages/setting/pages/play_gesture_set.dart @@ -58,11 +58,11 @@ class _PlayGesturePageState extends State { }, ); if (result != null) { - GlobalDataCache().fullScreenGestureMode = FullScreenGestureMode + GlobalDataCache.fullScreenGestureMode = FullScreenGestureMode .values .firstWhere((element) => element.values == result); fullScreenGestureMode = - GlobalDataCache().fullScreenGestureMode.index; + GlobalDataCache.fullScreenGestureMode.index; setting.put( SettingBoxKey.fullScreenGestureMode, fullScreenGestureMode); SmartDialog.showToast('设置成功'); diff --git a/lib/pages/setting/play_setting.dart b/lib/pages/setting/play_setting.dart index e191d8fd..7090bfaf 100644 --- a/lib/pages/setting/play_setting.dart +++ b/lib/pages/setting/play_setting.dart @@ -155,7 +155,7 @@ class _PlaySettingState extends State { setKey: SettingBoxKey.enablePlayerControlAnimation, defaultVal: true, callFn: (bool val) { - GlobalDataCache().enablePlayerControlAnimation = val; + GlobalDataCache.enablePlayerControlAnimation = val; }), SetSwitchItem( title: '港澳台模式', diff --git a/lib/pages/setting/style_setting.dart b/lib/pages/setting/style_setting.dart index 5b59397e..54b97ea5 100644 --- a/lib/pages/setting/style_setting.dart +++ b/lib/pages/setting/style_setting.dart @@ -175,7 +175,7 @@ class _StyleSettingState extends State { SettingBoxKey.defaultPicQa, picQuality); Get.back(); settingController.picQuality.value = picQuality; - GlobalDataCache().imgQuality = picQuality; + GlobalDataCache.imgQuality = picQuality; SmartDialog.showToast('设置成功'); }, child: const Text('确定'), diff --git a/lib/pages/video/detail/introduction/view.dart b/lib/pages/video/detail/introduction/view.dart index 451173dd..417548d5 100644 --- a/lib/pages/video/detail/introduction/view.dart +++ b/lib/pages/video/detail/introduction/view.dart @@ -169,8 +169,8 @@ class _VideoInfoState extends State with TickerProviderStateMixin { owner = widget.videoDetail!.owner; enableAi = setting.get(SettingBoxKey.enableAi, defaultValue: true); - _expandableCtr = ExpandableController( - initialExpanded: GlobalDataCache().enableAutoExpand); + _expandableCtr = + ExpandableController(initialExpanded: GlobalDataCache.enableAutoExpand); } // 收藏 @@ -556,7 +556,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { } Widget actionGrid(BuildContext context, videoIntroController) { - final actionTypeSort = GlobalDataCache().actionTypeSort; + final actionTypeSort = GlobalDataCache.actionTypeSort; Map menuListWidgets = { 'like': Obx( diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 5d31858f..e0a6d07f 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -52,7 +52,7 @@ class ReplyItem extends StatelessWidget { @override Widget build(BuildContext context) { final bool isOwner = int.parse(replyItem!.member!.mid!) == - (GlobalDataCache().userInfo?.mid ?? -1); + (GlobalDataCache.userInfo?.mid ?? -1); return Material( child: InkWell( // 点击整个评论区 评论详情/回复 @@ -415,7 +415,7 @@ class ReplyItemRow extends StatelessWidget { onLongPress: () { feedBack(); final bool isOwner = int.parse(replyItem!.member!.mid!) == - (GlobalDataCache().userInfo?.mid ?? -1); + (GlobalDataCache.userInfo?.mid ?? -1); showModalBottomSheet( context: context, useRootNavigator: true, diff --git a/lib/pages/video/detail/widgets/ai_detail.dart b/lib/pages/video/detail/widgets/ai_detail.dart index 64327553..c17591fb 100644 --- a/lib/pages/video/detail/widgets/ai_detail.dart +++ b/lib/pages/video/detail/widgets/ai_detail.dart @@ -18,7 +18,7 @@ class AiDetail extends StatelessWidget { Widget build(BuildContext context) { return Container( padding: const EdgeInsets.only(left: 16, right: 16), - height: GlobalDataCache().sheetHeight, + height: GlobalDataCache.sheetHeight, child: Column( children: [ _buildHeader(context), diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index de4cd9df..b69d96bb 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -278,19 +278,18 @@ class PlPlayerController { // 添加一个私有构造函数 PlPlayerController._internal(this.videoType) { - final cache = GlobalDataCache(); - isOpenDanmu.value = cache.isOpenDanmu; - blockTypes = cache.blockTypes; - showArea = cache.showArea; - opacityVal = cache.opacityVal; - fontSizeVal = cache.fontSizeVal; - danmakuDurationVal = cache.danmakuDurationVal; - strokeWidth = cache.strokeWidth; - playRepeat = cache.playRepeat; - _playbackSpeed.value = cache.playbackSpeed; - enableAutoLongPressSpeed = cache.enableAutoLongPressSpeed; - _longPressSpeed.value = cache.longPressSpeed; - speedsList = cache.speedsList; + isOpenDanmu.value = GlobalDataCache.isOpenDanmu; + blockTypes = GlobalDataCache.blockTypes; + showArea = GlobalDataCache.showArea; + opacityVal = GlobalDataCache.opacityVal; + fontSizeVal = GlobalDataCache.fontSizeVal; + danmakuDurationVal = GlobalDataCache.danmakuDurationVal; + strokeWidth = GlobalDataCache.strokeWidth; + playRepeat = GlobalDataCache.playRepeat; + _playbackSpeed.value = GlobalDataCache.playbackSpeed; + enableAutoLongPressSpeed = GlobalDataCache.enableAutoLongPressSpeed; + _longPressSpeed.value = GlobalDataCache.longPressSpeed; + speedsList = GlobalDataCache.speedsList; // _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) { // if (status == PlayerStatus.playing) { // WakelockPlus.enable(); @@ -1047,13 +1046,12 @@ class PlPlayerController { /// 缓存本次弹幕选项 cacheDanmakuOption() { - final cache = GlobalDataCache(); - cache.blockTypes = blockTypes; - cache.showArea = showArea; - cache.opacityVal = opacityVal; - cache.fontSizeVal = fontSizeVal; - cache.danmakuDurationVal = danmakuDurationVal; - cache.strokeWidth = strokeWidth; + GlobalDataCache.blockTypes = blockTypes; + GlobalDataCache.showArea = showArea; + GlobalDataCache.opacityVal = opacityVal; + GlobalDataCache.fontSizeVal = fontSizeVal; + GlobalDataCache.danmakuDurationVal = danmakuDurationVal; + GlobalDataCache.strokeWidth = strokeWidth; localCache.put(LocalCacheKey.danmakuBlockType, blockTypes); localCache.put(LocalCacheKey.danmakuShowArea, showArea); diff --git a/lib/plugin/pl_player/view.dart b/lib/plugin/pl_player/view.dart index 990661bc..c73bc55f 100644 --- a/lib/plugin/pl_player/view.dart +++ b/lib/plugin/pl_player/view.dart @@ -89,7 +89,7 @@ class _PLVideoPlayerState extends State late bool enableBackgroundPlay; late double screenWidth; final FullScreenGestureMode fullScreenGestureMode = - GlobalDataCache().fullScreenGestureMode; + GlobalDataCache.fullScreenGestureMode; // 用于记录上一次全屏切换手势触发时间,避免误触 DateTime? lastFullScreenToggleTime; @@ -136,7 +136,7 @@ class _PLVideoPlayerState extends State screenWidth = Get.size.width; animationController = AnimationController( vsync: this, - duration: GlobalDataCache().enablePlayerControlAnimation + duration: GlobalDataCache.enablePlayerControlAnimation ? const Duration(milliseconds: 150) : const Duration(milliseconds: 10), ); diff --git a/lib/utils/global_data_cache.dart b/lib/utils/global_data_cache.dart index 3321c660..ea673859 100644 --- a/lib/utils/global_data_cache.dart +++ b/lib/utils/global_data_cache.dart @@ -11,48 +11,48 @@ Box videoStorage = GStorage.video; Box userInfoCache = GStorage.userInfo; class GlobalDataCache { - late int imgQuality; - late FullScreenGestureMode fullScreenGestureMode; - late bool enablePlayerControlAnimation; - late List actionTypeSort; - late double sheetHeight; - String? wWebid; + static late int imgQuality; + static late FullScreenGestureMode fullScreenGestureMode; + static late bool enablePlayerControlAnimation; + static late List actionTypeSort; + static late double sheetHeight; + static String? wWebid; /// 播放器相关 // 弹幕开关 - late bool isOpenDanmu; + static late bool isOpenDanmu; // 弹幕屏蔽类型 - late List blockTypes; + static late List blockTypes; // 弹幕展示区域 - late double showArea; + static late double showArea; // 弹幕透明度 - late double opacityVal; + static late double opacityVal; // 弹幕字体大小 - late double fontSizeVal; + static late double fontSizeVal; // 弹幕显示时间 - late double danmakuDurationVal; + static late double danmakuDurationVal; // 弹幕描边宽度 - late double strokeWidth; + static late double strokeWidth; // 播放器循环模式 - late PlayRepeat playRepeat; + static late PlayRepeat playRepeat; // 播放器默认播放速度 - late double playbackSpeed; + static late double playbackSpeed; // 播放器自动长按速度 - late bool enableAutoLongPressSpeed; + static late bool enableAutoLongPressSpeed; // 播放器长按速度 - late double longPressSpeed; + static late double longPressSpeed; // 播放器速度列表 - late List speedsList; + static late List speedsList; // 用户信息 - UserInfoData? userInfo; + static UserInfoData? userInfo; // 搜索历史 - late List historyCacheList; - // - late bool enableSearchSuggest = true; + static late List historyCacheList; + // 搜索建议 + static late bool enableSearchSuggest; // 简介默认展开 - late bool enableAutoExpand = false; - // - late bool enableDynamicSwitch = true; + static late bool enableAutoExpand; + // 动态切换 + static late bool enableDynamicSwitch; // 私有构造函数 GlobalDataCache._(); @@ -64,7 +64,7 @@ class GlobalDataCache { factory GlobalDataCache() => _instance; // 异步初始化方法 - Future initialize() async { + static Future initialize() async { imgQuality = await setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); // 设置全局变量 fullScreenGestureMode = FullScreenGestureMode.values[setting.get( diff --git a/lib/utils/login.dart b/lib/utils/login.dart index 9dde1cb1..159de81d 100644 --- a/lib/utils/login.dart +++ b/lib/utils/login.dart @@ -118,7 +118,7 @@ class LoginUtils { Request.dio.options.headers['cookie'] = ''; userInfoCache.put('userInfoCache', null); localCache.put(LocalCacheKey.accessKey, {'mid': -1, 'value': ''}); - GlobalDataCache().userInfo = null; + GlobalDataCache.userInfo = null; await refreshLoginStatus(false); } } From 1ac152bb49ed159cd7366a20f23227accd882a75 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Wed, 20 Nov 2024 22:45:25 +0800 Subject: [PATCH 2/3] feat: dlna switch --- lib/pages/setting/extra_setting.dart | 6 ++++ .../video/detail/widgets/header_control.dart | 33 ++++++++++--------- lib/utils/global_data_cache.dart | 3 ++ lib/utils/storage.dart | 3 +- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lib/pages/setting/extra_setting.dart b/lib/pages/setting/extra_setting.dart index fdc62f13..3e82f2bd 100644 --- a/lib/pages/setting/extra_setting.dart +++ b/lib/pages/setting/extra_setting.dart @@ -190,6 +190,12 @@ class _ExtraSettingState extends State { setKey: SettingBoxKey.enableRelatedVideo, defaultVal: true, ), + const SetSwitchItem( + title: '视频投屏开关', + subTitle: '打开后将在播放器右上角显示投屏入口', + setKey: SettingBoxKey.enableDlna, + defaultVal: false, + ), ListTile( dense: false, title: Text('评论展示', style: titleStyle), diff --git a/lib/pages/video/detail/widgets/header_control.dart b/lib/pages/video/detail/widgets/header_control.dart index f22bf846..bc9167d5 100644 --- a/lib/pages/video/detail/widgets/header_control.dart +++ b/lib/pages/video/detail/widgets/header_control.dart @@ -16,6 +16,7 @@ import 'package:pilipala/pages/video/detail/index.dart'; import 'package:pilipala/pages/video/detail/introduction/widgets/menu_row.dart'; import 'package:pilipala/plugin/pl_player/index.dart'; import 'package:pilipala/plugin/pl_player/models/play_repeat.dart'; +import 'package:pilipala/utils/global_data_cache.dart'; import 'package:pilipala/utils/storage.dart'; import 'package:pilipala/services/shutdown_timer_service.dart'; import '../../../../http/danmaku.dart'; @@ -1237,22 +1238,24 @@ class _HeaderControlState extends State { // ), // fuc: () => _.screenshot(), // ), - ComBtn( - icon: const Icon( - Icons.cast, - size: 19, - color: Colors.white, + if (GlobalDataCache.enableDlna) ...[ + ComBtn( + icon: const Icon( + Icons.cast, + size: 19, + color: Colors.white, + ), + fuc: () async { + showDialog( + context: context, + builder: (BuildContext context) { + return LiveDlnaPage( + datasource: widget.videoDetailCtr!.videoUrl); + }, + ); + }, ), - fuc: () async { - showDialog( - context: context, - builder: (BuildContext context) { - return LiveDlnaPage( - datasource: widget.videoDetailCtr!.videoUrl); - }, - ); - }, - ), + ], if (isFullScreen.value) ...[ SizedBox( width: 56, diff --git a/lib/utils/global_data_cache.dart b/lib/utils/global_data_cache.dart index ea673859..a421f829 100644 --- a/lib/utils/global_data_cache.dart +++ b/lib/utils/global_data_cache.dart @@ -53,6 +53,8 @@ class GlobalDataCache { static late bool enableAutoExpand; // 动态切换 static late bool enableDynamicSwitch; + // 投屏开关 + static bool enableDlna = false; // 私有构造函数 GlobalDataCache._(); @@ -120,5 +122,6 @@ class GlobalDataCache { setting.get(SettingBoxKey.enableAutoExpand, defaultValue: false); enableDynamicSwitch = setting.get(SettingBoxKey.enableDynamicSwitch, defaultValue: true); + enableDlna = setting.get(SettingBoxKey.enableDlna, defaultValue: false); } } diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index a5b36768..49a5c734 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -115,7 +115,8 @@ class SettingBoxKey { enableAi = 'enableAi', enableAutoExpand = 'enableAutoExpand', defaultHomePage = 'defaultHomePage', - enableRelatedVideo = 'enableRelatedVideo'; + enableRelatedVideo = 'enableRelatedVideo', + enableDlna = 'enableDlna'; /// 外观 static const String themeMode = 'themeMode', From b824b75bc64f5b45a784965a99424282c3b69bc9 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 23 Nov 2024 00:01:16 +0800 Subject: [PATCH 3/3] opt: enableDlna switch callFn --- lib/pages/setting/extra_setting.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pages/setting/extra_setting.dart b/lib/pages/setting/extra_setting.dart index 3e82f2bd..004f3e9c 100644 --- a/lib/pages/setting/extra_setting.dart +++ b/lib/pages/setting/extra_setting.dart @@ -190,11 +190,14 @@ class _ExtraSettingState extends State { setKey: SettingBoxKey.enableRelatedVideo, defaultVal: true, ), - const SetSwitchItem( + SetSwitchItem( title: '视频投屏开关', subTitle: '打开后将在播放器右上角显示投屏入口', setKey: SettingBoxKey.enableDlna, defaultVal: false, + callFn: (bool val) { + GlobalDataCache.enableDlna = val; + }, ), ListTile( dense: false,