v9
This commit is contained in:
@@ -3,11 +3,32 @@ import '../router/app_router_delegate.dart';
|
||||
import 'app_navigation_rail.dart';
|
||||
import 'app_top_bar/app_top_bar.dart';
|
||||
|
||||
class AppNavigation extends StatelessWidget {
|
||||
const AppNavigation({super.key});
|
||||
class AppNavigation extends StatefulWidget {
|
||||
final Widget navigator;
|
||||
|
||||
const AppNavigation({super.key,required this.navigator});
|
||||
|
||||
@override
|
||||
State<AppNavigation> createState() => _AppNavigationState();
|
||||
}
|
||||
|
||||
class _AppNavigationState extends State<AppNavigation> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
print('======_AppNavigationState#initState==============');
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
print('======_AppNavigationState#dispose==============');
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print('=======AppNavigation#build===============');
|
||||
double px1 = 1/View.of(context).devicePixelRatio;
|
||||
return Scaffold(
|
||||
body: Row(
|
||||
@@ -19,10 +40,7 @@ class AppNavigation extends StatelessWidget {
|
||||
const AppTopBar(),
|
||||
Divider(height: px1,),
|
||||
Expanded(
|
||||
child: Router(
|
||||
routerDelegate: router,
|
||||
backButtonDispatcher: RootBackButtonDispatcher(),
|
||||
),
|
||||
child: widget.navigator,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:iroute/components/components.dart';
|
||||
import '../router/app_router_delegate.dart';
|
||||
import '../router/iroute_config.dart';
|
||||
import '../router/routes.dart';
|
||||
|
||||
class AppNavigationRail extends StatefulWidget {
|
||||
const AppNavigationRail({super.key});
|
||||
@@ -11,13 +12,6 @@ class AppNavigationRail extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _AppNavigationRailState extends State<AppNavigationRail> {
|
||||
final List<MenuMeta> deskNavBarMenus = const [
|
||||
MenuMeta(label: '颜色板', icon: Icons.color_lens_outlined, path: '/color'),
|
||||
MenuMeta(label: '计数器', icon: Icons.add_chart, path: '/counter'),
|
||||
MenuMeta(label: '排序', icon: Icons.sort, path: '/sort'),
|
||||
MenuMeta(label: '我的', icon: Icons.person, path: '/user'),
|
||||
MenuMeta(label: '设置', icon: Icons.settings, path: '/settings'),
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -54,14 +48,14 @@ class _AppNavigationRailState extends State<AppNavigationRail> {
|
||||
);
|
||||
}
|
||||
|
||||
RegExp _segReg = RegExp(r'/\w+');
|
||||
RegExp _segReg = RegExp(r'/app/\w+');
|
||||
|
||||
int? get activeIndex {
|
||||
String path = router.path;
|
||||
RegExpMatch? match = _segReg.firstMatch(path);
|
||||
if (match == null) return null;
|
||||
String? target = match.group(0);
|
||||
int index = deskNavBarMenus.indexWhere((menu) => menu.path == target);
|
||||
int index = deskNavBarMenus.indexWhere((menu) => menu.path!.contains(target??''));
|
||||
if (index == -1) return null;
|
||||
return index;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:iroute/components/components.dart';
|
||||
import '../../router/app_router_delegate.dart';
|
||||
import '../../router/routes.dart';
|
||||
import '../../router/views/route_back_indicator.dart';
|
||||
import 'app_router_editor.dart';
|
||||
import 'history_view_icon.dart';
|
||||
@@ -54,16 +55,6 @@ class RouterIndicator extends StatefulWidget {
|
||||
State<RouterIndicator> createState() => _RouterIndicatorState();
|
||||
}
|
||||
|
||||
Map<String, String> kRouteLabelMap = {
|
||||
'/color': '颜色板',
|
||||
'/color/add': '添加颜色',
|
||||
'/color/detail': '颜色详情',
|
||||
'/counter': '计数器',
|
||||
'/sort': '可视化排序算法',
|
||||
'/sort/settings': '排序配置',
|
||||
'/user': '我的',
|
||||
'/settings': '系统设置',
|
||||
};
|
||||
|
||||
class _RouterIndicatorState extends State<RouterIndicator> {
|
||||
@override
|
||||
@@ -107,7 +98,9 @@ class _RouterIndicatorState extends State<RouterIndicator> {
|
||||
for (String segment in uri.pathSegments) {
|
||||
to += '/$segment';
|
||||
String label = kRouteLabelMap[to] ?? '未知路由';
|
||||
result.add(BreadcrumbItem(to: to, label: label, active: to == distPath));
|
||||
if(label.isNotEmpty){
|
||||
result.add(BreadcrumbItem(to: to, label: label, active: to == distPath));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:iroute/components/components.dart';
|
||||
import '../../router/app_router_delegate.dart';
|
||||
import '../../router/iroute.dart';
|
||||
import '../../router/routes.dart';
|
||||
import '../../router/iroute_config.dart';
|
||||
import 'app_top_bar.dart';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user