This commit is contained in:
toly
2023-12-16 12:40:32 +08:00
parent ab2778a22b
commit 01fdf966c5
593 changed files with 8995 additions and 27753 deletions

View File

@@ -1,6 +1,9 @@
import '../../../app/res/fx_icon.dart';
Map<String,dynamic> animaMenus = {
'path' : '/anima',
'label' : '动画-流光幻影',
'icon': FxIcon.icon_anima,
'children': [
{
'path' : '/chapter1',

View File

@@ -0,0 +1,32 @@
import '../../../app/res/fx_icon.dart';
Map<String, dynamic> dashboard = {
'path': '/dashboard',
'label': '面板总览',
'icon': FxIcon.dashboard,
'children': [
{
'path': '/view',
'label': '小册全集',
},
{
'path': '/chat',
'label': '读者交流',
'children': [
{
'path': '/a',
'label': '第一交流区',
},
{
'path': '/b',
'label': '第二交流区',
},
{
'path': '/c',
'label': '第三交流区',
},
]
},
],
};

View File

@@ -1,5 +1,9 @@
import 'package:flutter/material.dart';
import 'package:iroute/app/res/fx_icon.dart';
Map<String, dynamic> drawMenus = {
'path': '/draw',
'icon': FxIcon.icon_paint,
'label': '绘制-妙笔生花',
'children': [
{

View File

@@ -1,6 +1,9 @@
import '../../../app/res/fx_icon.dart';
Map<String,dynamic> dreamMenus = {
'path' : '/dream',
'label' : '基础-梦始之地',
'icon': FxIcon.icon_dream,
'children': [
{
'path' : '/chapter1',

View File

@@ -1,6 +1,10 @@
import '../../../app/res/fx_icon.dart';
Map<String,dynamic> layoutMenus = {
'path' : '/layout',
'label' : '布局-薪火相传',
'icon': FxIcon.icon_layout,
'children': [
{
'path' : '/chapter1',

View File

@@ -0,0 +1,9 @@
class MenuHistory {
final String menuLabel;
final String menuPath;
MenuHistory({
required this.menuLabel,
required this.menuPath,
});
}

View File

@@ -0,0 +1,200 @@
import 'package:flutter/cupertino.dart';
import 'package:go_router/go_router.dart';
import 'package:toly_menu/toly_menu.dart';
import '../menu_tree.dart';
import 'menu_history.dart';
class MenuScope extends InheritedNotifier<MenuStore> {
const MenuScope({super.key, required super.child, super.notifier});
static MenuStore of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<MenuScope>()!.notifier!;
}
static MenuStore read(BuildContext context) {
return context.getInheritedWidgetOfExactType<MenuScope>()!.notifier!;
}
}
class MenuStore with ChangeNotifier {
late MenuState _state;
MenuState get state => _state;
final GoRouter goRouter;
final List<MenuHistory> _history = [];
List<MenuHistory> get history => _history;
MenuStore({
List<String> expandMenus = const [],
required this.goRouter,
required String activeMenu,
}) {
_state = MenuState(
expandMenus: expandMenus,
activeMenu: activeMenu,
items: rootMenu.children,
);
_history.add(MenuHistory(
menuLabel: pathName(activeMenu) ?? activeMenu,
menuPath: activeMenu,
));
goRouter.routerDelegate.addListener(_onRouterChange);
}
MenuNode? get currentNode => queryMenuNodeByPath(
MenuNode(
path: '',
label: '',
deep: -1,
children: _state.items,
),
_state.activeMenu);
String? pathName(String path) => queryMenuNodeByPath(
MenuNode(
path: '',
label: '',
deep: -1,
children: _state.items,
),
path)
?.label;
void selectMenuPath(String path) {
print("======================selectMenuPath:$path======${_shouldAddHistory}==============");
MenuNode root = MenuNode(
path: '',
label: '',
deep: -1,
children: _state.items,
);
List<MenuNode> result = findNodes(root, Uri.parse(path), 0, '/', []);
if (result.isNotEmpty) {
List<String> expandMenus = [];
if (result.length > 1) {
expandMenus.addAll(
result.sublist(0, result.length - 1).map((e) => e.path).toList());
}
if(_shouldAddHistory){
_history.add(MenuHistory(
menuLabel: result.last.label,
menuPath: result.last.path,
));
}else{
_shouldAddHistory = true;
}
_state = state.copyWith(
activeMenu: result.last.path, expandMenus: expandMenus);
}
}
bool _shouldAddHistory = true;
void selectHistory(String path) {
_shouldAddHistory = false;
goRouter.go(path);
}
void closeHistory(MenuHistory history) {
int index = _history.indexOf(history);
if(_history.length==1){
return;
}
if(state.activeMenu!=history.menuPath){
_history.remove(history);
notifyListeners();
return;
}
MenuHistory nextActiveHistory;
if(index==_history.length-1){
///
nextActiveHistory = _history[_history.length-2];
}else{
nextActiveHistory = _history[index+1];
}
_history.remove(history);
selectHistory(nextActiveHistory.menuPath);
}
List<MenuNode> findNodes(
MenuNode node,
Uri uri,
int deep,
String prefix,
List<MenuNode> result,
) {
List<String> parts = uri.pathSegments;
if (deep > parts.length - 1) {
return result;
}
String target = parts[deep];
if (node.children.isNotEmpty) {
target = prefix + target;
List<MenuNode> nodes =
node.children.where((e) => e.path == target).toList();
bool match = nodes.isNotEmpty;
if (match) {
MenuNode matched = nodes.first;
result.add(matched);
String nextPrefix = '${matched.path}/';
findNodes(matched, uri, ++deep, nextPrefix, result);
}
}
return result;
}
MenuNode? queryMenuNodeByPath(MenuNode node, String path) {
if (node.path == path) {
return node;
}
if (node.children.isNotEmpty) {
for (int i = 0; i < node.children.length; i++) {
MenuNode? result = queryMenuNodeByPath(node.children[i], path);
if (result != null) {
return result;
}
}
}
return null;
}
void select(MenuNode menu) {
if (menu.isLeaf) {
_state = state.copyWith(activeMenu: menu.path);
goRouter.go(menu.path);
_history.add(MenuHistory(
menuLabel: menu.label,
menuPath: menu.path,
));
// notifyListeners();
} else {
List<String> menus = [];
String path = menu.path.substring(1);
List<String> parts = path.split('/');
if (parts.isNotEmpty) {
String path = '';
for (String part in parts) {
path += '/$part';
menus.add(path);
}
}
if (state.expandMenus.contains(menu.path)) {
menus.remove(menu.path);
}
_state = state.copyWith(expandMenus: menus);
notifyListeners();
}
}
void _onRouterChange() {
String path =
goRouter.routerDelegate.currentConfiguration.last.matchedLocation;
if (path != state.activeMenu) {
selectMenuPath(path);
}
}
}

View File

@@ -1,6 +1,8 @@
import 'package:flutter/cupertino.dart';
import 'package:toly_menu/toly_menu.dart';
import 'anima.dart';
import 'dashboard.dart';
import 'draw.dart';
import 'dream.dart';
import 'layout.dart';
@@ -23,40 +25,13 @@ Map<String, dynamic> root = {
]
};
Map<String, dynamic> dashboard = {
'path': '/dashboard',
'label': '面板总览',
'children': [
{
'path': '/view',
'label': '小册全集',
},
{
'path': '/chat',
'label': '读者交流',
'children': [
{
'path': '/a',
'label': '第一交流区',
},
{
'path': '/b',
'label': '第二交流区',
},
{
'path': '/c',
'label': '第三交流区',
},
]
},
],
};
MenuNode get rootMenu => parser(root, -1, '');
MenuNode parser(Map<String, dynamic> data, int deep, String prefix) {
String path = data['path'];
String label = data['label'];
IconData? icon = data['icon'];
List<Map<String, dynamic>>? childrenMap = data['children'];
List<MenuNode> children = [];
if (childrenMap != null && childrenMap.isNotEmpty) {
@@ -66,6 +41,7 @@ MenuNode parser(Map<String, dynamic> data, int deep, String prefix) {
}
}
return MenuNode(
icon: icon,
path: prefix + path,
label: label,
deep: deep,

View File

@@ -1,6 +1,10 @@
import '../../../app/res/fx_icon.dart';
Map<String,dynamic> renderMenus = {
'path' : '/render',
'label' : '渲染-聚沙成塔',
'icon': FxIcon.icon_sun,
'children': [
{
'path' : '/chapter1',

View File

@@ -1,6 +1,10 @@
import '../../../app/res/fx_icon.dart';
Map<String,dynamic> scrollMenus = {
'path' : '/scroll',
'label' : '滑动-珠联璧合',
'icon': FxIcon.icon_scroll,
'children': [
{
'path' : '/chapter1',

View File

@@ -1,6 +1,9 @@
import '../../../app/res/fx_icon.dart';
Map<String,dynamic> touchMenus = {
'path' : '/touch',
'label' : '手势-执掌天下',
'icon': FxIcon.fill_shoushi,
'children': [
{
'path' : '/chapter1',

View File

@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:idraw/idraw.dart';
import 'package:iroute/pages/empty/empty_panel.dart';
final RouteBase animaRouters = GoRoute(
path: '/anima/chapter:index',
builder: (BuildContext context, GoRouterState state) {
String? index = state.pathParameters['index'];
switch(index){
case '1':
return const P01Page();
case '2':
return const P01Page();
case '3':
return const P03Page();
case '4':
return const P04Page();
case '5':
return const P05Page();
case '6':
return const P06Page();
case '7':
return const P07Page();
case '8':
return const P08Page();
case '9':
return const P09Page();
case '10':
return const P10Page();
case '11':
return const P11Page();
}
return const EmptyPanel(msg: '暂未实现');
},
);

View File

@@ -1,37 +1,39 @@
import 'package:components/components.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:iroute/v12/pages/empty/empty_panel.dart';
import 'package:iroute/navigation/router/routers/anima.dart';
import 'package:iroute/navigation/router/routers/dream.dart';
import 'package:iroute/navigation/router/routers/render.dart';
import 'package:iroute/navigation/router/routers/scroll.dart';
import 'package:iroute/navigation/router/routers/touch.dart';
import '../../../navigation/app_navigation.dart';
import '../../views/app_navigation.dart';
import '../../../pages/empty/empty_panel.dart';
import 'dashboard.dart';
import 'draw.dart';
import 'layout.dart';
final RouteBase appRoute = ShellRoute(
builder: (BuildContext context, GoRouterState state, Widget child) {
return BookAppNavigation(content: child);
return TolyBookNavigation(content: child);
},
routes: <RouteBase>[
dashboardRouters,
drawRouters,
// GoRoute(
// path: 'counter',
// builder: (BuildContext context, GoRouterState state) {
// return const CounterPage();
// }),
// sortRouters,
// GoRoute(
// path: 'user',
// builder: (BuildContext context, GoRouterState state) {
// return const UserPage();
// },
// ),
// GoRoute(
// path: 'settings',
// builder: (BuildContext context, GoRouterState state) {
// return const SettingPage();
// },
// ),
touchRouters,
dreamRouters,
scrollRouters,
renderRouters,
layoutRouters,
animaRouters,
GoRoute(
path: '/code',
builder: (BuildContext context, GoRouterState state) {
String? path = state.uri.queryParameters['path'];
return CodeView(path: path??'',);
},
),
GoRoute(
path: '/404',
builder: (BuildContext context, GoRouterState state) {

View File

@@ -1,82 +1,36 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:idraw/idraw.dart';
import 'package:iroute/pages/dashboard/chat_room.dart';
import 'package:iroute/pages/empty/empty_panel.dart';
final RouteBase drawRouters = GoRoute(
path: '/draw',
redirect: (_, state) {
if (state.fullPath == '/draw') {
return '/draw/chapter1';
}
return null;
},
routes: <RouteBase>[
GoRoute(
path: 'chapter1',
builder: (BuildContext context, GoRouterState state) {
path: '/draw/chapter:index',
builder: (BuildContext context, GoRouterState state) {
String? index = state.pathParameters['index'];
switch(index){
case '1':
return const P01Page();
},
),
GoRoute(
path: 'chapter2',
builder: (BuildContext context, GoRouterState state) {
case '2':
return const P02Page();
},
),
GoRoute(
path: 'chapter3',
builder: (BuildContext context, GoRouterState state) {
case '3':
return const P03Page();
},
),
GoRoute(
path: 'chapter4',
builder: (BuildContext context, GoRouterState state) {
case '4':
return const P04Page();
},
),
GoRoute(
path: 'chapter5',
builder: (BuildContext context, GoRouterState state) {
case '5':
return const P05Page();
},
),
GoRoute(
path: 'chapter6',
builder: (BuildContext context, GoRouterState state) {
case '6':
return const P06Page();
},
),
GoRoute(
path: 'chapter7',
builder: (BuildContext context, GoRouterState state) {
case '7':
return const P07Page();
},
),
GoRoute(
path: 'chapter8',
builder: (BuildContext context, GoRouterState state) {
case '8':
return const P08Page();
},
),
GoRoute(
path: 'chapter9',
builder: (BuildContext context, GoRouterState state) {
case '9':
return const P09Page();
},
),
GoRoute(
path: 'chapter10',
builder: (BuildContext context, GoRouterState state) {
case '10':
return const P10Page();
},
),
GoRoute(
path: 'chapter11',
builder: (BuildContext context, GoRouterState state) {
case '11':
return const P11Page();
},
),
],
}
return const EmptyPanel(msg: '暂未实现');
},
);

View File

@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:idraw/idraw.dart';
import 'package:iroute/pages/empty/empty_panel.dart';
final RouteBase dreamRouters = GoRoute(
path: '/dream/chapter:index',
builder: (BuildContext context, GoRouterState state) {
String? index = state.pathParameters['index'];
switch(index){
case '1':
return const P01Page();
case '2':
return const P01Page();
case '3':
return const P03Page();
case '4':
return const P04Page();
case '5':
return const P05Page();
case '6':
return const P06Page();
case '7':
return const P07Page();
case '8':
return const P08Page();
case '9':
return const P09Page();
case '10':
return const P10Page();
case '11':
return const P11Page();
}
return const EmptyPanel(msg: '暂未实现');
},
);

View File

@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:idraw/idraw.dart';
import 'package:iroute/pages/empty/empty_panel.dart';
final RouteBase layoutRouters = GoRoute(
path: '/layout/chapter:index',
builder: (BuildContext context, GoRouterState state) {
String? index = state.pathParameters['index'];
switch(index){
case '1':
return const P01Page();
case '2':
return const P01Page();
case '3':
return const P03Page();
case '4':
return const P04Page();
case '5':
return const P05Page();
case '6':
return const P06Page();
case '7':
return const P07Page();
case '8':
return const P08Page();
case '9':
return const P09Page();
case '10':
return const P10Page();
case '11':
return const P11Page();
}
return const EmptyPanel(msg: '暂未实现');
},
);

View File

@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:idraw/idraw.dart';
import 'package:iroute/pages/empty/empty_panel.dart';
final RouteBase renderRouters = GoRoute(
path: '/render/chapter:index',
builder: (BuildContext context, GoRouterState state) {
String? index = state.pathParameters['index'];
switch(index){
case '1':
return const P01Page();
case '2':
return const P01Page();
case '3':
return const P03Page();
case '4':
return const P04Page();
case '5':
return const P05Page();
case '6':
return const P06Page();
case '7':
return const P07Page();
case '8':
return const P08Page();
case '9':
return const P09Page();
case '10':
return const P10Page();
case '11':
return const P11Page();
}
return const EmptyPanel(msg: '暂未实现');
},
);

View File

@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:idraw/idraw.dart';
import 'package:iroute/pages/empty/empty_panel.dart';
final RouteBase scrollRouters = GoRoute(
path: '/scroll/chapter:index',
builder: (BuildContext context, GoRouterState state) {
String? index = state.pathParameters['index'];
switch(index){
case '1':
return const P01Page();
case '2':
return const P01Page();
case '3':
return const P03Page();
case '4':
return const P04Page();
case '5':
return const P05Page();
case '6':
return const P06Page();
case '7':
return const P07Page();
case '8':
return const P08Page();
case '9':
return const P09Page();
case '10':
return const P10Page();
case '11':
return const P11Page();
}
return const EmptyPanel(msg: '暂未实现');
},
);

View File

@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:idraw/idraw.dart';
import 'package:iroute/pages/empty/empty_panel.dart';
final RouteBase touchRouters = GoRoute(
path: '/touch/chapter:index',
builder: (BuildContext context, GoRouterState state) {
String? index = state.pathParameters['index'];
switch(index){
case '1':
return const P01Page();
case '2':
return const P01Page();
case '3':
return const P03Page();
case '4':
return const P04Page();
case '5':
return const P05Page();
case '6':
return const P06Page();
case '7':
return const P07Page();
case '8':
return const P08Page();
case '9':
return const P09Page();
case '10':
return const P10Page();
case '11':
return const P11Page();
}
return const EmptyPanel(msg: '暂未实现');
},
);