diff --git a/lib/main.dart b/lib/main.dart index b74c730a4..02bd4ce7b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -294,6 +294,7 @@ class MyApp extends StatelessWidget { supportedLocales: const [Locale("zh", "CN"), Locale("en", "US")], initialRoute: '/', getPages: Routes.getPages, + defaultTransition: Pref.pageTransition, builder: FlutterSmartDialog.init( toastBuilder: (String msg) => CustomToast(msg: msg), loadingBuilder: (msg) => LoadingWidget(msg: msg), diff --git a/lib/pages/setting/models/extra_settings.dart b/lib/pages/setting/models/extra_settings.dart index 009d90c91..6117e371b 100644 --- a/lib/pages/setting/models/extra_settings.dart +++ b/lib/pages/setting/models/extra_settings.dart @@ -480,7 +480,7 @@ List get extraSettings => [ setKey: SettingBoxKey.refreshDragPercentage, getSubtitle: () => '当前滑动距离: ${Pref.refreshDragPercentage}x', onTap: (setState) async { - double? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SlideDialog( @@ -509,7 +509,7 @@ List get extraSettings => [ setKey: SettingBoxKey.refreshDisplacement, getSubtitle: () => '当前指示器高度: ${Pref.refreshDisplacement}', onTap: (setState) async { - double? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SlideDialog( @@ -585,7 +585,7 @@ List get extraSettings => [ getSubtitle: () => '当前:「${Pref.superResolutionType.title}」\n默认设置对番剧生效, 其他视频默认关闭\n超分辨率需要启用硬件解码, 若启用硬件解码后仍然不生效, 尝试切换硬件解码器为 auto-copy', onTap: (setState) async { - SuperResolutionType? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -992,7 +992,7 @@ List get extraSettings => [ getSubtitle: () => '当前优先展示「${ReplySortType.values[Pref.replySortType].title}」', onTap: (setState) async { - int? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -1018,7 +1018,7 @@ List get extraSettings => [ getSubtitle: () => '当前优先展示「${DynamicsTabType.values[Pref.defaultDynamicType].label}」', onTap: (setState) async { - int? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -1044,7 +1044,7 @@ List get extraSettings => [ leading: const Icon(Icons.tab), getSubtitle: () => '当前优先展示「${Pref.memberTab.title}」', onTap: (setState) async { - MemberTabType? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( diff --git a/lib/pages/setting/models/play_settings.dart b/lib/pages/setting/models/play_settings.dart index 263897283..eacc823a4 100644 --- a/lib/pages/setting/models/play_settings.dart +++ b/lib/pages/setting/models/play_settings.dart @@ -137,7 +137,7 @@ List get playSettings => [ getSubtitle: () => '当前选择偏好:${SubtitlePrefType.values[Pref.subtitlePreferenceV2].desc}', onTap: (setState) async { - int? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -284,7 +284,7 @@ List get playSettings => [ getSubtitle: () => '当前全屏方向:${FullScreenMode.values[Pref.fullScreenMode].desc}', onTap: (setState) async { - int? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -309,7 +309,7 @@ List get playSettings => [ getSubtitle: () => '当前展示方式:${BtmProgressBehavior.values[Pref.btmProgressBehavior].desc}', onTap: (setState) async { - int? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( diff --git a/lib/pages/setting/models/style_settings.dart b/lib/pages/setting/models/style_settings.dart index ebe5e5e50..7499da282 100644 --- a/lib/pages/setting/models/style_settings.dart +++ b/lib/pages/setting/models/style_settings.dart @@ -22,7 +22,6 @@ import 'package:PiliPlus/pages/setting/widgets/multi_select_dialog.dart'; import 'package:PiliPlus/pages/setting/widgets/select_dialog.dart'; import 'package:PiliPlus/pages/setting/widgets/slide_dialog.dart'; import 'package:PiliPlus/plugin/pl_player/utils/fullscreen.dart'; -import 'package:PiliPlus/router/app_pages.dart'; import 'package:PiliPlus/utils/global_data.dart'; import 'package:PiliPlus/utils/storage.dart'; import 'package:PiliPlus/utils/storage_key.dart'; @@ -115,20 +114,19 @@ List get styleSettings => [ settingsType: SettingsType.normal, title: '页面过渡动画', leading: const Icon(Icons.animation), - getSubtitle: () => '当前:${CustomGetPage.pageTransition.name}', + getSubtitle: () => '当前:${Pref.pageTransition.name}', onTap: (setState) async { - Transition? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( title: '页面过渡动画', - value: CustomGetPage.pageTransition, + value: Pref.pageTransition, values: Transition.values.map((e) => (e, e.name)).toList(), ); }, ); if (result != null) { - CustomGetPage.pageTransition = result; await GStorage.setting.put(SettingBoxKey.pageTransition, result.index); SmartDialog.showToast('重启生效'); setState(); @@ -155,7 +153,7 @@ List get styleSettings => [ SettingsModel( settingsType: SettingsType.normal, onTap: (setState) async { - double? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SlideDialog( @@ -206,7 +204,7 @@ List get styleSettings => [ leading: const Icon(Icons.person_outlined), getSubtitle: () => '当前:${Pref.upPanelPosition.label}', onTap: (setState) async { - UpPanelPosition? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -240,7 +238,7 @@ List get styleSettings => [ SettingsModel( settingsType: SettingsType.normal, onTap: (setState) async { - DynamicBadgeMode? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -271,7 +269,7 @@ List get styleSettings => [ SettingsModel( settingsType: SettingsType.normal, onTap: (setState) async { - DynamicBadgeMode? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -521,7 +519,7 @@ List get styleSettings => [ SettingsModel( settingsType: SettingsType.normal, onTap: (setState) async { - double? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SlideDialog( @@ -554,7 +552,7 @@ List get styleSettings => [ SettingsModel( settingsType: SettingsType.normal, onTap: (setState) async { - ThemeType? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -601,7 +599,7 @@ List get styleSettings => [ SettingsModel( settingsType: SettingsType.normal, onTap: (setState) async { - int? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( diff --git a/lib/pages/setting/models/video_settings.dart b/lib/pages/setting/models/video_settings.dart index 28a60a5cd..5b60c9855 100644 --- a/lib/pages/setting/models/video_settings.dart +++ b/lib/pages/setting/models/video_settings.dart @@ -56,7 +56,7 @@ List get videoSettings => [ getSubtitle: () => '当前使用:${VideoUtils.cdnService.desc},部分 CDN 可能失效,如无法播放请尝试切换', onTap: (setState) async { - CDNService? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return const CdnSelectDialog(); @@ -145,7 +145,7 @@ List get videoSettings => [ getSubtitle: () => '当前画质:${VideoQuality.fromCode(Pref.defaultVideoQa).desc}', onTap: (setState) async { - int? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -168,7 +168,7 @@ List get videoSettings => [ getSubtitle: () => '当前画质:${VideoQuality.fromCode(Pref.defaultVideoQaCellular).desc}', onTap: (setState) async { - int? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -194,7 +194,7 @@ List get videoSettings => [ getSubtitle: () => '当前音质:${AudioQuality.fromCode(Pref.defaultAudioQa).desc}', onTap: (setState) async { - int? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -217,7 +217,7 @@ List get videoSettings => [ getSubtitle: () => '当前音质:${AudioQuality.fromCode(Pref.defaultAudioQaCellular).desc}', onTap: (setState) async { - int? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -242,7 +242,7 @@ List get videoSettings => [ leading: const Icon(Icons.video_settings_outlined), getSubtitle: () => '当前画质:${LiveQuality.fromCode(Pref.liveQuality)?.desc}', onTap: (setState) async { - int? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -265,7 +265,7 @@ List get videoSettings => [ getSubtitle: () => '当前画质:${LiveQuality.fromCode(Pref.liveQualityCellular)?.desc}', onTap: (setState) async { - int? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -288,7 +288,7 @@ List get videoSettings => [ getSubtitle: () => '首选解码格式:${VideoDecodeFormatType.fromCode(Pref.defaultDecode).description},请根据设备支持情况与需求调整', onTap: (setState) async { - String? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -313,7 +313,7 @@ List get videoSettings => [ '非杜比视频次选:${VideoDecodeFormatType.fromCode(Pref.secondDecode).description},仍无则选择首个提供的解码格式', leading: const Icon(Icons.swap_horizontal_circle_outlined), onTap: (setState) async { - String? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( @@ -355,7 +355,7 @@ List get videoSettings => [ leading: const Icon(Icons.view_timeline_outlined), getSubtitle: () => '当前:${Pref.videoSync}(此项即mpv的--video-sync)', onTap: (setState) async { - String? result = await showDialog( + final result = await showDialog( context: Get.context!, builder: (context) { return SelectDialog( diff --git a/lib/pages/setting/pages/color_select.dart b/lib/pages/setting/pages/color_select.dart index 7da0d9641..7cbc3b1f3 100644 --- a/lib/pages/setting/pages/color_select.dart +++ b/lib/pages/setting/pages/color_select.dart @@ -64,7 +64,7 @@ class _ColorSelectPageState extends State { children: [ ListTile( onTap: () async { - ThemeType? result = await showDialog( + final result = await showDialog( context: context, builder: (context) { return SelectDialog( diff --git a/lib/pages/setting/widgets/multi_select_dialog.dart b/lib/pages/setting/widgets/multi_select_dialog.dart index d39550dd6..eaf709536 100644 --- a/lib/pages/setting/widgets/multi_select_dialog.dart +++ b/lib/pages/setting/widgets/multi_select_dialog.dart @@ -33,31 +33,34 @@ class _MultiSelectDialogState extends State> { clipBehavior: Clip.hardEdge, title: Text(widget.title), contentPadding: const EdgeInsets.only(top: 12), - content: SingleChildScrollView( - child: Column( - mainAxisSize: MainAxisSize.min, - children: widget.values.entries.map((i) { - return Builder( - builder: (context) { - bool isChecked = _tempValues.contains(i.key); - return CheckboxListTile( - dense: true, - value: isChecked, - controlAffinity: ListTileControlAffinity.leading, - title: Text( - i.value, - style: theme.textTheme.titleMedium!, - ), - onChanged: (value) { - isChecked - ? _tempValues.remove(i.key) - : _tempValues.add(i.key); - (context as Element).markNeedsBuild(); - }, - ); - }, - ); - }).toList(), + content: Material( + type: .transparency, + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + children: widget.values.entries.map((i) { + return Builder( + builder: (context) { + bool isChecked = _tempValues.contains(i.key); + return CheckboxListTile( + dense: true, + value: isChecked, + controlAffinity: ListTileControlAffinity.leading, + title: Text( + i.value, + style: theme.textTheme.titleMedium!, + ), + onChanged: (value) { + isChecked + ? _tempValues.remove(i.key) + : _tempValues.add(i.key); + (context as Element).markNeedsBuild(); + }, + ); + }, + ); + }).toList(), + ), ), ), actionsPadding: const EdgeInsets.only(left: 16, right: 16, bottom: 12), diff --git a/lib/pages/setting/widgets/normal_item.dart b/lib/pages/setting/widgets/normal_item.dart index 9c7355ee8..9c5c4e973 100644 --- a/lib/pages/setting/widgets/normal_item.dart +++ b/lib/pages/setting/widgets/normal_item.dart @@ -39,7 +39,9 @@ class _NormalItemState extends State { return ListTile( contentPadding: widget.contentPadding, onTap: () => widget.onTap?.call(() { - setState(() {}); + if (mounted) { + setState(() {}); + } }), title: Text( widget.title ?? widget.getTitle!(), diff --git a/lib/pages/setting/widgets/ordered_multi_select_dialog.dart b/lib/pages/setting/widgets/ordered_multi_select_dialog.dart index a59467a8d..b1c7639c7 100644 --- a/lib/pages/setting/widgets/ordered_multi_select_dialog.dart +++ b/lib/pages/setting/widgets/ordered_multi_select_dialog.dart @@ -37,39 +37,42 @@ class _OrderedMultiSelectDialogState clipBehavior: Clip.hardEdge, title: Text(widget.title), contentPadding: const EdgeInsets.only(top: 12), - content: SingleChildScrollView( - child: Column( - mainAxisSize: MainAxisSize.min, - children: widget.values.entries.map((i) { - return Builder( - builder: (context) { - return OrderedCheckboxListTile( - dense: true, - value: _tempValues[i.key], - title: Text( - i.value, - style: theme.textTheme.titleMedium!, - ), - onChanged: (value) { - if (value == null) { - _tempValues[i.key] = _tempValues.length + 1; - (context as Element).markNeedsBuild(); - } else { - final pos = _tempValues.remove(i.key)!; - if (pos == _tempValues.length + 1) { + content: Material( + type: .transparency, + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + children: widget.values.entries.map((i) { + return Builder( + builder: (context) { + return OrderedCheckboxListTile( + dense: true, + value: _tempValues[i.key], + title: Text( + i.value, + style: theme.textTheme.titleMedium!, + ), + onChanged: (value) { + if (value == null) { + _tempValues[i.key] = _tempValues.length + 1; (context as Element).markNeedsBuild(); } else { - _tempValues.updateAll( - (key, value) => value > pos ? value - 1 : value, - ); - setState(() {}); + final pos = _tempValues.remove(i.key)!; + if (pos == _tempValues.length + 1) { + (context as Element).markNeedsBuild(); + } else { + _tempValues.updateAll( + (key, value) => value > pos ? value - 1 : value, + ); + setState(() {}); + } } - } - }, - ); - }, - ); - }).toList(), + }, + ); + }, + ); + }).toList(), + ), ), ), actionsPadding: const EdgeInsets.only(left: 16, right: 16, bottom: 12), diff --git a/lib/pages/setting/widgets/select_dialog.dart b/lib/pages/setting/widgets/select_dialog.dart index 200ed822d..c532f58c4 100644 --- a/lib/pages/setting/widgets/select_dialog.dart +++ b/lib/pages/setting/widgets/select_dialog.dart @@ -38,27 +38,30 @@ class SelectDialog extends StatelessWidget { ? const BoxConstraints(maxWidth: 320, minWidth: 320) : null, contentPadding: const EdgeInsets.symmetric(vertical: 12), - content: SingleChildScrollView( - child: RadioGroup( - onChanged: (v) => Navigator.of(context).pop(v ?? value), - groupValue: value, - child: Column( - mainAxisSize: MainAxisSize.min, - children: List.generate( - values.length, - (index) { - final item = values[index]; - return RadioListTile( - toggleable: toggleable, - dense: true, - value: item.$1, - title: Text( - item.$2, - style: titleMedium, - ), - subtitle: subtitleBuilder?.call(context, index), - ); - }, + content: Material( + type: .transparency, + child: SingleChildScrollView( + child: RadioGroup( + onChanged: (v) => Navigator.of(context).pop(v ?? value), + groupValue: value, + child: Column( + mainAxisSize: MainAxisSize.min, + children: List.generate( + values.length, + (index) { + final item = values[index]; + return RadioListTile( + toggleable: toggleable, + dense: true, + value: item.$1, + title: Text( + item.$2, + style: titleMedium, + ), + subtitle: subtitleBuilder?.call(context, index), + ); + }, + ), ), ), ), diff --git a/lib/pages/setting/widgets/switch_item.dart b/lib/pages/setting/widgets/switch_item.dart index 8402c2431..8063f2b95 100644 --- a/lib/pages/setting/widgets/switch_item.dart +++ b/lib/pages/setting/widgets/switch_item.dart @@ -91,7 +91,9 @@ class _SetSwitchItemState extends State { ); val = true; SmartDialog.showToast('重启生效'); - setState(() {}); + if (mounted) { + setState(() {}); + } }, child: const Text('确认'), ), @@ -113,7 +115,9 @@ class _SetSwitchItemState extends State { if (widget.needReboot) { SmartDialog.showToast('重启生效'); } - setState(() {}); + if (mounted) { + setState(() {}); + } } @override diff --git a/lib/pages/video/widgets/header_control.dart b/lib/pages/video/widgets/header_control.dart index 475bf3b5b..6d68dba6c 100644 --- a/lib/pages/video/widgets/header_control.dart +++ b/lib/pages/video/widgets/header_control.dart @@ -1156,7 +1156,7 @@ class HeaderControlState extends State ), onTap: () async { Get.back(); - CDNService? result = await showDialog( + final result = await showDialog( context: context, builder: (context) { return CdnSelectDialog( diff --git a/lib/router/app_pages.dart b/lib/router/app_pages.dart index abeea3e3a..0c7fb26af 100644 --- a/lib/router/app_pages.dart +++ b/lib/router/app_pages.dart @@ -71,8 +71,6 @@ import 'package:PiliPlus/pages/webdav/view.dart'; import 'package:PiliPlus/pages/webview/view.dart'; import 'package:PiliPlus/pages/whisper/view.dart'; import 'package:PiliPlus/pages/whisper_detail/view.dart'; -import 'package:PiliPlus/utils/storage_pref.dart'; -import 'package:flutter/material.dart'; import 'package:get/get.dart'; class Routes { @@ -234,18 +232,12 @@ class Routes { ]; } -class CustomGetPage extends GetPage { +class CustomGetPage extends GetPage { CustomGetPage({ required super.name, required super.page, - bool fullscreen = false, - super.transitionDuration, - }) : super( - curve: Curves.linear, - transition: pageTransition, - showCupertinoParallax: false, - popGesture: false, - fullscreenDialog: fullscreen, - ); - static Transition pageTransition = Transition.values[Pref.pageTransition]; + super.popGesture = false, + super.fullscreenDialog = false, + super.showCupertinoParallax = false, + }); } diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index 618b6d54f..5a8e809de 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -678,10 +678,11 @@ abstract class Pref { static bool get enableMYBar => _setting.get(SettingBoxKey.enableMYBar, defaultValue: true); - static int get pageTransition => _setting.get( - SettingBoxKey.pageTransition, - defaultValue: Transition.native.index, - ); + static Transition get pageTransition => + Transition.values[_setting.get( + SettingBoxKey.pageTransition, + defaultValue: Transition.native.index, + )]; static bool get enableQuickDouble => _setting.get(SettingBoxKey.enableQuickDouble, defaultValue: true);