基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
fix(navigation): fix tab router mismatch (#2547)
LiggMax3bfd5d1f31e3
diff --git a/lib/pages/index_module.dart b/lib/pages/index_module.dartindex 26ca4380..9f3ed184 100644--- a/lib/pages/index_module.dart+++ b/lib/pages/index_module.dart@@ -46,7 +46,7 @@ final tabModule = createModule(..addSingleton<TimelineController>(TimelineController.new)..route('/',- child: (context, state) => const IndexPage(),+ child: (context, state) => IndexPage(location: state.uri.path),transition: _tabTransition,children: (sub) {subdiff --git a/lib/pages/index_page.dart b/lib/pages/index_page.dartindex c59788b5..2f9f3c2b 100644--- a/lib/pages/index_page.dart+++ b/lib/pages/index_page.dart@@ -2,8 +2,9 @@ import 'package:flutter/material.dart';import 'package:kazumi/pages/menu/menu.dart';class IndexPage extends StatefulWidget {- //const IndexPage({super.key});- const IndexPage({super.key});+ const IndexPage({super.key, required this.location});++ final String location;@overrideState<IndexPage> createState() => _IndexPageState();@@ -12,6 +13,6 @@ class IndexPage extends StatefulWidget {class _IndexPageState extends State<IndexPage> with WidgetsBindingObserver {@overrideWidget build(BuildContext context) {- return const ScaffoldMenu();+ return ScaffoldMenu(location: widget.location);}}diff --git a/lib/pages/menu/menu.dart b/lib/pages/menu/menu.dartindex e68e78a5..af87a54c 100644--- a/lib/pages/menu/menu.dart+++ b/lib/pages/menu/menu.dart@@ -8,7 +8,9 @@ import 'package:kazumi/pages/menu/route_visibility.dart';import 'package:kazumi/pages/router.dart';class ScaffoldMenu extends StatefulWidget {- const ScaffoldMenu({super.key});+ const ScaffoldMenu({super.key, required this.location});++ final String location;@overrideState<ScaffoldMenu> createState() => _ScaffoldMenu();@@ -16,12 +18,21 @@ class ScaffoldMenu extends StatefulWidget {class _ScaffoldMenu extends State<ScaffoldMenu> with RouteAware {final _outletKey = GlobalKey<RouterOutletState>();+ late int _selectedIndex = menu.indexForPath(widget.location);DateTime? _lastExitPromptAt;/// The shell sits at the bottom of the root stack and stays mounted while/// other pages cover it, so it publishes that state for its subtree.bool _isCovered = false;+ @override+ void didUpdateWidget(covariant ScaffoldMenu oldWidget) {+ super.didUpdateWidget(oldWidget);+ if (oldWidget.location != widget.location) {+ _selectedIndex = menu.indexForPath(widget.location);+ }+ }+@overridevoid didChangeDependencies() {super.didChangeDependencies();@@ -52,12 +63,13 @@ class _ScaffoldMenu extends State<ScaffoldMenu> with RouteAware {void _selectDestination(int index) {_lastExitPromptAt = null;- final currentIndex =- menu.indexForPath(context.routeState(listen: false).uri.path);- if (index == currentIndex) {+ if (index == _selectedIndex) {return;}- _outletKey.currentState?.navigate('/tab${menu.getPath(index)}/');+ final outlet = _outletKey.currentState;+ if (outlet == null) return;+ outlet.navigate('/tab${menu.getPath(index)}/');+ setState(() => _selectedIndex = index);}void _handleSystemBack(BuildContext context) {@@ -66,9 +78,7 @@ class _ScaffoldMenu extends State<ScaffoldMenu> with RouteAware {return;}- final currentIndex =- menu.indexForPath(context.routeState(listen: false).uri.path);- if (currentIndex != 0) {+ if (_selectedIndex != 0) {_selectDestination(0);return;}@@ -88,7 +98,6 @@ class _ScaffoldMenu extends State<ScaffoldMenu> with RouteAware {@overrideWidget build(BuildContext context) {- final selectedIndex = menu.indexForPath(context.routeState().uri.path);return RouteVisibility(isCovered: _isCovered,child: PopScope(@@ -101,8 +110,8 @@ class _ScaffoldMenu extends State<ScaffoldMenu> with RouteAware {child: OrientationBuilder(builder: (context, orientation) {return orientation == Orientation.portrait- ? _bottomMenu(context, selectedIndex)- : _sideMenu(context, selectedIndex);+ ? _bottomMenu(context, _selectedIndex)+ : _sideMenu(context, _selectedIndex);},),),