基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
refactor(settings): simplify navigation and remove dead code
Prediditd780e997135a
diff --git a/lib/bean/settings/settings_detail_scaffold.dart b/lib/bean/settings/settings_detail_scaffold.dartindex 5fcc4779..37af9fa3 100644--- a/lib/bean/settings/settings_detail_scaffold.dart+++ b/lib/bean/settings/settings_detail_scaffold.dart@@ -1,27 +1,18 @@import 'package:flutter/material.dart';import 'package:kazumi/bean/appbar/sys_app_bar.dart';-/// Tells a settings detail page how the settings page is hosting it.-///-/// The scope wraps the settings outlet, including pushed detail routes.-/// Pages outside that outlet can still render as standalone routes.class SettingsPaneScope extends InheritedWidget {const SettingsPaneScope({super.key,required this.embedded,- this.showBackButton = false,- this.onBack,+ required this.showBackButton,+ required this.onBack,required super.child,});- /// Rendered as the right pane; the tab rail owns navigation.final bool embedded;-- /// A directly opened secondary route also needs a way back to its category.final bool showBackButton;-- /// Rendered as a single-pane detail; back returns to the category list.- final VoidCallback? onBack;+ final VoidCallback onBack;static SettingsPaneScope? of(BuildContext context) {return context.dependOnInheritedWidgetOfExactType<SettingsPaneScope>();diff --git a/lib/pages/settings/decoder_settings.dart b/lib/pages/settings/decoder_settings.dartindex 662f8bbe..a40c8f40 100644--- a/lib/pages/settings/decoder_settings.dart+++ b/lib/pages/settings/decoder_settings.dart@@ -12,15 +12,7 @@ class DecoderSettings extends StatefulWidget {}class _DecoderSettingsState extends State<DecoderSettings> {- late final ValueNotifier<String> decoder = ValueNotifier<String>(- GStorage.getSetting<String>(SettingsKeys.hardwareDecoder),- );-- @override- void dispose() {- decoder.dispose();- super.dispose();- }+ late String _decoder = GStorage.getSetting(SettingsKeys.hardwareDecoder);@overrideWidget build(BuildContext context) {@@ -30,13 +22,13 @@ class _DecoderSettingsState extends State<DecoderSettings> {sections: [SettingsRadioSection<String>(title: Text('选择不受支持的解码器将回退到软件解码'),- groupValue: decoder.value,+ groupValue: _decoder,onChanged: (String? value) {if (value != null) {GStorage.putSetting<String>(SettingsKeys.hardwareDecoder, value);setState(() {- decoder.value = value;+ _decoder = value;});}},diff --git a/lib/pages/settings/displaymode_settings.dart b/lib/pages/settings/displaymode_settings.dartindex 725bb3e0..4a08e28a 100644--- a/lib/pages/settings/displaymode_settings.dart+++ b/lib/pages/settings/displaymode_settings.dart@@ -20,12 +20,6 @@ class _SetDisplayModeState extends State<SetDisplayMode> {DisplayMode? active;DisplayMode? preferred;- final ValueNotifier<int> page = ValueNotifier<int>(0);- late final PageController controller = PageController()- ..addListener(() {- page.value = controller.page!.round();- });-@overridevoid initState() {super.initState();@@ -61,13 +55,6 @@ class _SetDisplayModeState extends State<SetDisplayMode> {return f;}- @override- void dispose() {- controller.dispose();- page.dispose();- super.dispose();- }-@overrideWidget build(BuildContext context) {return SettingsDetailScaffold(diff --git a/lib/pages/settings/proxy/proxy_editor_page.dart b/lib/pages/settings/proxy/proxy_editor_page.dartindex 41d496f2..d5195b90 100644--- a/lib/pages/settings/proxy/proxy_editor_page.dart+++ b/lib/pages/settings/proxy/proxy_editor_page.dart@@ -50,10 +50,8 @@ class _ProxyEditorPageState extends State<ProxyEditorPage> {await GStorage.putSetting(SettingsKeys.proxyUrl, url);await GStorage.putSetting(SettingsKeys.proxyTestUrl, testUrl);- // 重置配置状态,等待测试结果await GStorage.putSetting(SettingsKeys.proxyConfigured, false);- // 临时启用代理进行测试await GStorage.putSetting(SettingsKeys.proxyEnable, true);ProxyManager.applyProxy();diff --git a/lib/pages/settings/renderer_settings.dart b/lib/pages/settings/renderer_settings.dartindex 893d09d8..d405eb83 100644--- a/lib/pages/settings/renderer_settings.dart+++ b/lib/pages/settings/renderer_settings.dart@@ -12,15 +12,8 @@ class RendererSettings extends StatefulWidget {}class _RendererSettingsState extends State<RendererSettings> {- late final ValueNotifier<String> renderer = ValueNotifier<String>(- GStorage.getSetting<String>(SettingsKeys.androidVideoRenderer),- );-- @override- void dispose() {- renderer.dispose();- super.dispose();- }+ late String _renderer =+ GStorage.getSetting(SettingsKeys.androidVideoRenderer);@overrideWidget build(BuildContext context) {@@ -30,13 +23,13 @@ class _RendererSettingsState extends State<RendererSettings> {sections: [SettingsRadioSection<String>(title: Text('选择合适的渲染器以获得最佳播放体验'),- groupValue: renderer.value,+ groupValue: _renderer,onChanged: (String? value) {if (value != null) {GStorage.putSetting<String>(SettingsKeys.androidVideoRenderer, value);setState(() {- renderer.value = value;+ _renderer = value;});}},diff --git a/lib/pages/settings/settings_module.dart b/lib/pages/settings/settings_module.dartindex 42ccc39e..b6d06195 100644--- a/lib/pages/settings/settings_module.dart+++ b/lib/pages/settings/settings_module.dart@@ -33,7 +33,7 @@ final settingsModule = createModule(sub..route('/',transition: TransitionType.none,- child: (context, state) => const SettingsMenuPage())+ child: (context, state) => const SettingsIndexPage())..route('/sync',transition: TransitionType.none,child: (context, state) => const SyncSettingsPage())diff --git a/lib/pages/settings/settings_page.dart b/lib/pages/settings/settings_page.dartindex 22d1ec66..d99d7df2 100644--- a/lib/pages/settings/settings_page.dart+++ b/lib/pages/settings/settings_page.dart@@ -10,14 +10,12 @@ import 'package:kazumi/utils/constants.dart';class _SettingsCategory {const _SettingsCategory({- required this.id,required this.label,required this.description,required this.icon,required this.path,});- final String id;final String label;final String description;final IconData icon;@@ -36,21 +34,18 @@ const List<_SettingsGroup> _settingsGroups = [title: '播放',categories: [_SettingsCategory(- id: 'player',label: '播放设置',description: '解码、渲染与播放行为',icon: Icons.display_settings_rounded,path: '/settings/player',),_SettingsCategory(- id: 'danmaku',label: '弹幕设置',description: '弹幕来源与显示效果',icon: Icons.subtitles_rounded,path: '/settings/danmaku',),_SettingsCategory(- id: 'keyboard',label: '操作设置',description: '播放器按键映射',icon: Icons.keyboard_rounded,@@ -62,14 +57,12 @@ const List<_SettingsGroup> _settingsGroups = [title: '资源',categories: [_SettingsCategory(- id: 'plugin',label: '规则管理',description: '番剧资源规则',icon: Icons.extension_rounded,path: '/settings/plugin',),_SettingsCategory(- id: 'download',label: '下载设置',description: '并发数与弹幕缓存',icon: Icons.downloading_rounded,@@ -81,28 +74,24 @@ const List<_SettingsGroup> _settingsGroups = [title: '应用',categories: [_SettingsCategory(- id: 'theme',label: '外观设置',description: '主题、配色与字体',icon: Icons.palette_rounded,path: '/settings/theme',),_SettingsCategory(- id: 'interface',label: '界面设置',description: '启动、窗口行为与展示信息',icon: Icons.pages_rounded,path: '/settings/interface',),_SettingsCategory(- id: 'sync',label: '同步设置',description: '追番状态与多设备同步',icon: Icons.cloud_rounded,path: '/settings/sync',),_SettingsCategory(- id: 'proxy',label: '网络设置',description: '访问加速与代理',icon: Icons.language_rounded,@@ -114,21 +103,18 @@ const List<_SettingsGroup> _settingsGroups = [title: '其他',categories: [_SettingsCategory(- id: 'update',label: '更新设置',description: '应用与规则更新',icon: Icons.update_rounded,path: '/settings/update',),_SettingsCategory(- id: 'storage',label: '存储与日志',description: '图片缓存与错误日志',icon: Icons.storage_rounded,path: '/settings/storage',),_SettingsCategory(- id: 'about',label: '关于',description: '版本与开源信息',icon: Icons.info_outline_rounded,@@ -138,18 +124,23 @@ const List<_SettingsGroup> _settingsGroups = [),];+String _normalizePath(String path) =>+ path.endsWith('/') ? path.substring(0, path.length - 1) : path;++bool _isWithinPath(String location, String path) =>+ location == path || location.startsWith('$path/');+String _categoryPath(String location) {- if (location == '/settings' || location == '/settings/') {+ if (location == '/settings') {return '/settings/player';}- if (location.startsWith('/settings/bangumi') ||- location.startsWith('/settings/webdav')) {+ if (_isWithinPath(location, '/settings/bangumi') ||+ _isWithinPath(location, '/settings/webdav')) {return '/settings/sync';}for (final group in _settingsGroups) {for (final category in group.categories) {- if (location == category.path ||- location.startsWith('${category.path}/')) {+ if (_isWithinPath(location, category.path)) {return category.path;}}@@ -157,7 +148,12 @@ String _categoryPath(String location) {return location;}-/// The outlet stays mounted when the window crosses the layout breakpoint.+class _SettingsCategorySelected extends Notification {+ const _SettingsCategorySelected(this.path);++ final String path;+}+class SettingsPage extends StatefulWidget {const SettingsPage({super.key, required this.location});@@ -171,29 +167,29 @@ class _SettingsPageState extends State<SettingsPage> {final _outletKey = GlobalKey<RouterOutletState>();bool _canPopDetail = false;// Root pushes do not change routeState(), so keep this outlet's base local.- late String _location = widget.location;+ late String _location = _normalizePath(widget.location);++ bool get _isRoot => _location == '/settings';+ String get _selectedCategoryPath => _categoryPath(_location);+ bool get _isSecondaryRoute => !_isRoot && _location != _selectedCategoryPath;@overridevoid didUpdateWidget(covariant SettingsPage oldWidget) {super.didUpdateWidget(oldWidget);- if (oldWidget.location != widget.location) _location = widget.location;+ if (oldWidget.location != widget.location) {+ _location = _normalizePath(widget.location);+ }}void _navigateTo(String path) {_outletKey.currentState!.navigate(path);- setState(() => _location = path);+ setState(() => _location = _normalizePath(path));}- void _backToMenu() {+ void _backToParent() {final outlet = _outletKey.currentState;if (outlet != null && !outlet.maybePop()) {- final location = _location;- final category = _categoryPath(location);- _navigateTo(location.replaceFirst(RegExp(r'/$'), '') != category &&- location != '/settings/' &&- location != '/settings'- ? category- : '/settings/');+ _navigateTo(_isSecondaryRoute ? _selectedCategoryPath : '/settings/');}}@@ -203,14 +199,12 @@ class _SettingsPageState extends State<SettingsPage> {@overrideWidget build(BuildContext context) {- final location = _location;- final isRoot = location == '/settings' || location == '/settings/';return LayoutBuilder(builder: (context, constraints) {final wide = constraints.maxWidth > LayoutBreakpoint.compact['width']!;return PopScope(- canPop: !_canPopDetail && (wide || isRoot),+ canPop: !_canPopDetail && (wide || _isRoot),onPopInvokedWithResult: (didPop, result) {- if (!didPop) _backToMenu();+ if (!didPop) _backToParent();},child: Scaffold(appBar: wide@@ -231,7 +225,7 @@ class _SettingsPageState extends State<SettingsPage> {offstage: !wide,child: _SettingsMenu(wide: true,- location: location,+ selectedPath: _selectedCategoryPath,onSelect: _navigateTo,),),@@ -239,19 +233,23 @@ class _SettingsPageState extends State<SettingsPage> {Expanded(child: SettingsPaneScope(embedded: wide,- showBackButton: !isRoot &&- location.replaceFirst(RegExp(r'/$'), '') !=- _categoryPath(location),- onBack: _backToMenu,- child: NotificationListener<NavigationNotification>(+ showBackButton: _isSecondaryRoute,+ onBack: _backToParent,+ child: NotificationListener<_SettingsCategorySelected>(onNotification: (notification) {- if (_canPopDetail != notification.canHandlePop) {- setState(- () => _canPopDetail = notification.canHandlePop);- }- return false;+ _navigateTo(notification.path);+ return true;},- child: RouterOutlet(key: _outletKey),+ child: NotificationListener<NavigationNotification>(+ onNotification: (notification) {+ if (_canPopDetail != notification.canHandlePop) {+ setState(() =>+ _canPopDetail = notification.canHandlePop);+ }+ return false;+ },+ child: RouterOutlet(key: _outletKey),+ ),),),),@@ -264,9 +262,8 @@ class _SettingsPageState extends State<SettingsPage> {}}-/// The index route supplies the default detail only in the two-pane layout.-class SettingsMenuPage extends StatelessWidget {- const SettingsMenuPage({super.key});+class SettingsIndexPage extends StatelessWidget {+ const SettingsIndexPage({super.key});@overrideWidget build(BuildContext context) {@@ -282,10 +279,7 @@ class SettingsMenuPage extends StatelessWidget {),body: _SettingsMenu(wide: false,- location: '/settings/',- onSelect: (path) => context- .findAncestorStateOfType<_SettingsPageState>()!- ._navigateTo(path),+ onSelect: (path) => _SettingsCategorySelected(path).dispatch(context),),);}@@ -294,16 +288,14 @@ class SettingsMenuPage extends StatelessWidget {class _SettingsMenu extends StatelessWidget {const _SettingsMenu({required this.wide,- required this.location,+ this.selectedPath,required this.onSelect,});final bool wide;- final String location;+ final String? selectedPath;final ValueChanged<String> onSelect;- String get categoryPath => _categoryPath(location);-@overrideWidget build(BuildContext context) {return ScrollConfiguration(@@ -322,8 +314,7 @@ class _SettingsMenu extends StatelessWidget {for (final category in group.categories)_RailDestination(category: category,- selected: categoryPath == category.path ||- categoryPath.startsWith('${category.path}/'),+ selected: selectedPath == category.path,onTap: () => onSelect(category.path),),] elsediff --git a/test/widget_test.dart b/test/widget_test.dartdeleted file mode 100644index 0db063e3..00000000--- a/test/widget_test.dart+++ /dev/null@@ -1,12 +0,0 @@-// This is a basic Flutter widget test.-//-// To perform an interaction with a widget in your test, use the WidgetTester-// utility in the flutter_test package. For example, you can send tap and scroll-// gestures. You can also use WidgetTester to find child widgets in the widget-// tree, read text, and verify that the values of widget properties are correct.--import 'package:flutter_test/flutter_test.dart';--void main() {- testWidgets('Counter increments smoke test', (WidgetTester tester) async {});-}