v10
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:iroute/v9/app/navigation/router/views/navigator_scope.dart';
|
||||
import 'views/navigator_scope.dart';
|
||||
import 'iroute.dart';
|
||||
import 'iroute_config.dart';
|
||||
import 'route_history_manager.dart';
|
||||
@@ -62,8 +62,7 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
|
||||
// final List<IRouteConfig> _pathStack = [];
|
||||
|
||||
bool get canPop =>
|
||||
_configs.where((e) => e.routeStyle == RouteStyle.push).isNotEmpty;
|
||||
bool get canPop => _configs.where((e) => e.routeStyle == RouteStyle.push).isNotEmpty;
|
||||
|
||||
final Map<String, Completer<dynamic>> _completerMap = {};
|
||||
|
||||
@@ -129,75 +128,6 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
configs: _configs,
|
||||
notFindPageBuilder: (notFindPageBuilder ?? _defaultNotFindPageBuilder),
|
||||
);
|
||||
// return Navigator(
|
||||
// onPopPage: _onPopPage,
|
||||
// pages: [
|
||||
// MaterialPage(child: NavigatorScope(
|
||||
// cellNode: cellNode,
|
||||
// onPopPage: _onPopPage,
|
||||
// configs: _configs,
|
||||
// notFindPageBuilder: (notFindPageBuilder ?? _defaultNotFindPageBuilder),
|
||||
// ))
|
||||
// ],
|
||||
// );
|
||||
}
|
||||
|
||||
List<Page> _buildPages(BuildContext context, List<IRouteConfig> configs) {
|
||||
IRouteConfig top = configs.last;
|
||||
List<IRouteConfig> bottoms =
|
||||
_configs.sublist(0, _configs.length - 1).toList();
|
||||
List<Page> pages = [];
|
||||
List<Page> topPages = _buildPageByPathFromTree(context, top);
|
||||
pages = _buildLivePageByPathList(context, bottoms, top, topPages);
|
||||
pages.addAll(topPages);
|
||||
return pages;
|
||||
}
|
||||
|
||||
List<Page> _buildLivePageByPathList(
|
||||
BuildContext context,
|
||||
List<IRouteConfig> paths,
|
||||
IRouteConfig curConfig,
|
||||
List<Page> curPages,
|
||||
) {
|
||||
List<Page> pages = [];
|
||||
if (paths.isNotEmpty) {
|
||||
for (IRouteConfig path in paths) {
|
||||
if (path != curConfig) {
|
||||
pages.addAll(_buildPageByPathFromTree(context, path));
|
||||
}
|
||||
}
|
||||
|
||||
/// 去除和 curPages 中重复的界面
|
||||
pages
|
||||
.removeWhere((page) => curPages.map((e) => e.key).contains(page.key));
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
|
||||
List<Page> _buildPageByPathFromTree(
|
||||
BuildContext context, IRouteConfig config) {
|
||||
List<Page> result = [];
|
||||
List<IRouteNode> iRoutes = rootRoute.find(config.path);
|
||||
if (iRoutes.isNotEmpty) {
|
||||
for (int i = 0; i < iRoutes.length; i++) {
|
||||
IRouteNode iroute = iRoutes[i];
|
||||
config = config.copyWith(path: iroute.path);
|
||||
Page? page;
|
||||
if (iroute is NotFindNode) {
|
||||
page = (notFindPageBuilder ?? _defaultNotFindPageBuilder)(
|
||||
context, config);
|
||||
} else {
|
||||
page = iroute.createPage(context, config);
|
||||
}
|
||||
if (page != null) {
|
||||
result.add(page);
|
||||
}
|
||||
if (iroute is CellIRoute) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -223,7 +153,7 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
|
||||
_completerMap.remove(path);
|
||||
}
|
||||
|
||||
if (_configs.length > 1) {
|
||||
if (canPop) {
|
||||
_configs.removeLast();
|
||||
notifyListeners();
|
||||
} else {
|
||||
|
||||
@@ -79,7 +79,7 @@ Map<String, String> kRouteLabelMap = {
|
||||
'/app/color/add': '添加颜色',
|
||||
'/app/color/detail': '颜色详情',
|
||||
'/app/counter': '计数器',
|
||||
'/app/sort': '可视化排序算法',
|
||||
'/app/sort': '排序算法',
|
||||
'/app/sort/player': '演示',
|
||||
'/app/sort/settings': '排序配置',
|
||||
'/app/user': '我的',
|
||||
|
||||
@@ -28,7 +28,6 @@ class _AppNavigationState extends State<AppNavigation> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print('=======AppNavigation#build===============');
|
||||
double px1 = 1/View.of(context).devicePixelRatio;
|
||||
return Scaffold(
|
||||
body: Row(
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:iroute/v9/app/navigation/router/iroute_config.dart';
|
||||
import '../player/sort_player.dart';
|
||||
import '../../../../app/navigation/router/app_router_delegate.dart';
|
||||
import '../settings/sort_setting.dart';
|
||||
import '../../../../app/navigation/router/iroute_config.dart';
|
||||
import 'sort_button.dart';
|
||||
|
||||
import '../../functions.dart';
|
||||
@@ -84,7 +81,7 @@ class SortRailPanel extends StatelessWidget {
|
||||
options: sortNameMap.values.toList(),
|
||||
onSelected: (name) {
|
||||
state.selectName(name);
|
||||
router.changePath('/sort/player');
|
||||
router.changePath('/app/sort/player');
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -93,64 +90,6 @@ class SortRailPanel extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class SortNavigatorScope extends StatefulWidget {
|
||||
const SortNavigatorScope({super.key});
|
||||
|
||||
@override
|
||||
State<SortNavigatorScope> createState() => _SortNavigatorScopeState();
|
||||
}
|
||||
|
||||
class _SortNavigatorScopeState extends State<SortNavigatorScope> {
|
||||
@override
|
||||
void initState() {
|
||||
router.addListener(_update);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
router.removeListener(_update);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String path = router.path;
|
||||
List<Page> pages = buildPagesByPath(context, path);
|
||||
return Navigator(
|
||||
onPopPage: _onPopPage,
|
||||
pages: pages,
|
||||
);
|
||||
}
|
||||
|
||||
bool _onPopPage(Route<dynamic> route, result) {
|
||||
return route.didPop(result);
|
||||
}
|
||||
|
||||
List<Page> buildPagesByPath(BuildContext context, String path) {
|
||||
if (path == '/sort/settings') {
|
||||
return [
|
||||
const MaterialPage(key: ValueKey('/sort/player'), child: SortPlayer()),
|
||||
const MaterialPage(
|
||||
key: ValueKey('/sort/settings'),
|
||||
child: SortSettings(),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
const MaterialPage(
|
||||
key: ValueKey('/sort/player'),
|
||||
child: SortPlayer(),
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
void _update() {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
class SortSelectorPanel extends StatelessWidget {
|
||||
final String active;
|
||||
final ValueChanged<String> onSelected;
|
||||
|
||||
Reference in New Issue
Block a user