This commit is contained in:
toly
2023-11-11 11:37:41 +08:00
parent 8fb4bf57d6
commit 5396712cf9
17 changed files with 368 additions and 101 deletions

View File

@@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart'; import 'package:window_manager/window_manager.dart';
import 'v8/app.dart'; import 'v9/app.dart';
void main() { void main() {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();

View File

@@ -38,7 +38,7 @@ class _ColorPageState extends State<ColorPage> {
void _selectColor(Color color){ void _selectColor(Color color){
// String value = color.value.toRadixString(16); // String value = color.value.toRadixString(16);
// router.path = '/color/detail?color=$value'; // router.path = '/color/detail?color=$value';
router.changePath('/color/detail_error',extra: color); router.changePath('/color/detail',extra: color);
} }

View File

@@ -38,7 +38,7 @@ class _ColorPageState extends State<ColorPage> {
void _selectColor(Color color){ void _selectColor(Color color){
// String value = color.value.toRadixString(16); // String value = color.value.toRadixString(16);
// router.path = '/color/detail?color=$value'; // router.path = '/color/detail?color=$value';
router.changePath('/color/detail_error',extra: color); router.changePath('/color/detail',extra: color);
} }

View File

@@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:iroute/v9/app/navigation/router/views/navigator_scope.dart';
import 'iroute.dart'; import 'iroute.dart';
import 'iroute_config.dart'; import 'iroute_config.dart';
import 'route_history_manager.dart'; import 'route_history_manager.dart';
@@ -7,11 +8,12 @@ import 'routes.dart';
import 'views/not_find_view.dart'; import 'views/not_find_view.dart';
AppRouterDelegate router = AppRouterDelegate( AppRouterDelegate router = AppRouterDelegate(
initial: IRouteConfig(uri: Uri.parse('/color')), initial: IRouteConfig(
); uri: Uri.parse('/app/color'),
),
node: appRoute);
class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier { class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
/// 核心数据,路由配置数据列表 /// 核心数据,路由配置数据列表
final List<IRouteConfig> _configs = []; final List<IRouteConfig> _configs = [];
@@ -21,8 +23,11 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
final IRoutePageBuilder? notFindPageBuilder; final IRoutePageBuilder? notFindPageBuilder;
final IRouteNode node;
AppRouterDelegate({ AppRouterDelegate({
this.notFindPageBuilder, this.notFindPageBuilder,
required this.node,
required IRouteConfig initial, required IRouteConfig initial,
}) { }) {
_configs.add(initial); _configs.add(initial);
@@ -57,7 +62,8 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
// final List<IRouteConfig> _pathStack = []; // 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 = {}; final Map<String, Completer<dynamic>> _completerMap = {};
@@ -80,7 +86,7 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
} }
} }
void _handleChangeStyle(IRouteConfig config){ void _handleChangeStyle(IRouteConfig config) {
switch (config.routeStyle) { switch (config.routeStyle) {
case RouteStyle.push: case RouteStyle.push:
if (_configs.contains(config)) { if (_configs.contains(config)) {
@@ -89,9 +95,10 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
_configs.add(config); _configs.add(config);
break; break;
case RouteStyle.replace: case RouteStyle.replace:
List<IRouteConfig> liveRoutes = _configs.where((e) => e.keepAlive&&e!=config).toList(); List<IRouteConfig> liveRoutes =
_configs.where((e) => e.keepAlive && e != config).toList();
_configs.clear(); _configs.clear();
_configs.addAll([...liveRoutes,config]); _configs.addAll([...liveRoutes, config]);
break; break;
} }
} }
@@ -101,7 +108,7 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
bool forResult = false, bool forResult = false,
Object? extra, Object? extra,
bool keepAlive = false, bool keepAlive = false,
bool recordHistory = true, bool recordHistory = false,
RouteStyle style = RouteStyle.replace, RouteStyle style = RouteStyle.replace,
}) { }) {
return changeRoute(IRouteConfig( return changeRoute(IRouteConfig(
@@ -116,15 +123,29 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Navigator( return NavigatorScope(
node: node,
onPopPage: _onPopPage, onPopPage: _onPopPage,
pages: _buildPages(context, _configs), 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) { List<Page> _buildPages(BuildContext context, List<IRouteConfig> configs) {
IRouteConfig top = configs.last; IRouteConfig top = configs.last;
List<IRouteConfig> bottoms = _configs.sublist(0,_configs.length-1).toList(); List<IRouteConfig> bottoms =
_configs.sublist(0, _configs.length - 1).toList();
List<Page> pages = []; List<Page> pages = [];
List<Page> topPages = _buildPageByPathFromTree(context, top); List<Page> topPages = _buildPageByPathFromTree(context, top);
pages = _buildLivePageByPathList(context, bottoms, top, topPages); pages = _buildLivePageByPathList(context, bottoms, top, topPages);
@@ -145,8 +166,10 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
pages.addAll(_buildPageByPathFromTree(context, path)); pages.addAll(_buildPageByPathFromTree(context, path));
} }
} }
/// 去除和 curPages 中重复的界面 /// 去除和 curPages 中重复的界面
pages.removeWhere((page) => curPages.map((e) => e.key).contains(page.key)); pages
.removeWhere((page) => curPages.map((e) => e.key).contains(page.key));
} }
return pages; return pages;
} }
@@ -161,14 +184,15 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
config = config.copyWith(path: iroute.path); config = config.copyWith(path: iroute.path);
Page? page; Page? page;
if (iroute is NotFindNode) { if (iroute is NotFindNode) {
page = (notFindPageBuilder ?? _defaultNotFindPageBuilder)(context, config); page = (notFindPageBuilder ?? _defaultNotFindPageBuilder)(
context, config);
} else { } else {
page = iroute.createPage(context, config); page = iroute.createPage(context, config);
} }
if (page != null) { if (page != null) {
result.add(page); result.add(page);
} }
if(iroute is CellIRoute){ if (iroute is CellIRoute) {
break; break;
} }
} }
@@ -199,7 +223,7 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
_completerMap.remove(path); _completerMap.remove(path);
} }
if (_configs.isNotEmpty) { if (_configs.length > 1) {
_configs.removeLast(); _configs.removeLast();
notifyListeners(); notifyListeners();
} else { } else {

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:iroute/v9/app/navigation/router/views/navigator_scope.dart';
import 'iroute_config.dart'; import 'iroute_config.dart';
@@ -7,6 +8,8 @@ typedef IRoutePageBuilder = Page? Function(
IRouteConfig data, IRouteConfig data,
); );
typedef IRouteWidgetBuilder = Widget? Function( typedef IRouteWidgetBuilder = Widget? Function(
BuildContext context, BuildContext context,
IRouteConfig data, IRouteConfig data,
@@ -26,7 +29,15 @@ abstract class IRouteNode {
List<IRouteNode> find( List<IRouteNode> find(
String input, String input,
) { ) {
return findNodes(this, Uri.parse(input), 0, '/', []); String prefix = '/';
if (this is CellIRoute) {
input = input.replaceFirst(path, '');
if (path != '/') {
prefix = path + "/";
}
}
return findNodes(this, Uri.parse(input), 0, prefix, []);
} }
List<IRouteNode> findNodes( List<IRouteNode> findNodes(
@@ -43,6 +54,7 @@ abstract class IRouteNode {
String target = parts[deep]; String target = parts[deep];
if (node.children.isNotEmpty) { if (node.children.isNotEmpty) {
target = prefix + target; target = prefix + target;
List<IRouteNode> nodes = List<IRouteNode> nodes =
node.children.where((e) => e.path == target).toList(); node.children.where((e) => e.path == target).toList();
bool match = nodes.isNotEmpty; bool match = nodes.isNotEmpty;
@@ -103,14 +115,43 @@ class NotFindNode extends IRouteNode {
} }
} }
typedef CellBuilder = Widget Function(
BuildContext context,
IRouteConfig config,
Widget navigator,
);
typedef CellIRoutePageBuilder = Page? Function(
BuildContext context,
IRouteConfig data,
Widget child,
);
class CellIRoute extends IRouteNode {
final CellBuilder cellBuilder;
final CellIRoutePageBuilder? pageBuilder;
class CellIRoute extends IRoute {
const CellIRoute({ const CellIRoute({
required this.cellBuilder,
this.pageBuilder,
required super.path, required super.path,
super.pageBuilder, required super.children,
super.children,
super.widget,
}); });
}
typedef CellBuilder = Widget Function(BuildContext context,IRouteConfig config, CellIRoute cell); @override
Page? createPage(BuildContext context, IRouteConfig config) {
return null;
}
Page? createCellPage(BuildContext context, IRouteConfig config,
Widget child) {
if (pageBuilder != null) {
return pageBuilder!(context, config, child);
}
print("======CellIRoute#createCellPage${config.pageKey}=================");
return MaterialPage(
child: child,
key: config.pageKey,
);
}
}

View File

@@ -1,6 +1,10 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:iroute/components/components.dart';
import '../../../pages/login/login.dart';
import '../transition/no_transition_page.dart';
import '../../../pages/sort/views/player/sort_player.dart'; import '../../../pages/sort/views/player/sort_player.dart';
import 'iroute_config.dart'; import 'iroute_config.dart';
import '../views/app_navigation.dart';
import 'iroute.dart'; import 'iroute.dart';
import '../../../pages/color/color_add_page.dart'; import '../../../pages/color/color_add_page.dart';
import '../../../pages/color/color_detail_page.dart'; import '../../../pages/color/color_detail_page.dart';
@@ -11,37 +15,52 @@ import '../../../pages/settings/settings_page.dart';
import '../../../pages/sort/views/sort_page/sort_page.dart'; import '../../../pages/sort/views/sort_page/sort_page.dart';
import '../../../pages/sort/views/settings/sort_setting.dart'; import '../../../pages/sort/views/settings/sort_setting.dart';
IRoute rootRoute = const IRoute( CellIRoute appRoute = CellIRoute(
path: 'root', cellBuilder: (_, __, navigator) => AppNavigation(
navigator: navigator,
),
path: '/app',
children: [ children: [
IRoute( IRoute(
path: '/color', path: '/app/color',
widget: ColorPage(), widget: ColorPage(),
children: [ children: [
IRoute(path: '/color/detail', widgetBuilder: _buildColorDetail), IRoute(path: '/app/color/detail', widgetBuilder: _buildColorDetail),
IRoute(path: '/color/add', widget: ColorAddPage()), IRoute(path: '/app/color/add', widget: ColorAddPage()),
], ],
), ),
IRoute(path: '/counter', widget: CounterPage()), const IRoute(path: '/app/counter', widget: CounterPage()),
CellIRoute( CellIRoute(
path: '/sort', cellBuilder: (_, __, navigator) => SortNavigation(navigator: navigator),
widget: SortPage(), // pageBuilder: (_,config,child)=> NoTransitionPage(
// child: child,
// key: config.pageKey
// ),
path: '/app/sort',
children: [ children: [
IRoute( const IRoute(
path: '/sort/settings', path: '/app/sort/settings',
widget: SortSettings(), widget: SortSettings(),
), ),
IRoute( const IRoute(
path: '/sort/player', path: '/app/sort/player',
widget: SortPlayer(), widget: SortPlayer(),
), ),
], ],
), ),
IRoute(path: '/user', widget: UserPage()), const IRoute(path: '/app/user', widget: UserPage()),
IRoute(path: '/settings', widget: SettingPage()), const IRoute(path: '/app/settings', widget: SettingPage()),
], ],
); );
IRoute rootRoute = IRoute(path: '/', children: [
appRoute,
const IRoute(
path: '/login',
widget: LoginPage()
)
]);
Widget? _buildColorDetail(BuildContext context, IRouteConfig data) { Widget? _buildColorDetail(BuildContext context, IRouteConfig data) {
final Map<String, String> queryParams = data.uri.queryParameters; final Map<String, String> queryParams = data.uri.queryParameters;
String? selectedColor = queryParams['color']; String? selectedColor = queryParams['color'];
@@ -53,3 +72,24 @@ Widget? _buildColorDetail(BuildContext context, IRouteConfig data) {
} }
return ColorDetailPage(color: color); return ColorDetailPage(color: color);
} }
Map<String, String> kRouteLabelMap = {
'/app': '',
'/app/color': '颜色板',
'/app/color/add': '添加颜色',
'/app/color/detail': '颜色详情',
'/app/counter': '计数器',
'/app/sort': '可视化排序算法',
'/app/sort/player': '演示',
'/app/sort/settings': '排序配置',
'/app/user': '我的',
'/app/settings': '系统设置',
};
const List<MenuMeta> deskNavBarMenus = [
MenuMeta(label: '颜色板', icon: Icons.color_lens_outlined, path: '/app/color'),
MenuMeta(label: '计数器', icon: Icons.add_chart, path: '/app/counter'),
MenuMeta(label: '排序', icon: Icons.sort, path: '/app/sort/player'),
MenuMeta(label: '我的', icon: Icons.person, path: '/app/user'),
MenuMeta(label: '设置', icon: Icons.settings, path: '/app/settings'),
];

View File

@@ -0,0 +1,109 @@
import 'package:flutter/material.dart';
import '../iroute.dart';
import '../iroute_config.dart';
class NavigatorScope extends StatefulWidget {
final IRouteNode node;
final PopPageCallback onPopPage;
final List<IRouteConfig> configs;
final IRoutePageBuilder notFindPageBuilder;
const NavigatorScope({
super.key,
required this.node,
required this.onPopPage,
required this.configs,
required this.notFindPageBuilder,
});
@override
State<NavigatorScope> createState() => _NavigatorScopeState();
}
class _NavigatorScopeState extends State<NavigatorScope> {
@override
Widget build(BuildContext context) {
Widget content = Navigator(
onPopPage: widget.onPopPage,
pages: _buildPages(context, widget.configs),
);
if(widget.node is CellIRoute){
content = (widget.node as CellIRoute).cellBuilder(context,widget.configs.last,content);
}
return HeroControllerScope(
controller: MaterialApp.createMaterialHeroController(),
child: content,
);
}
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 = widget.node.find(config.path);
if (iRoutes.isNotEmpty) {
for (int i = 0; i < iRoutes.length; i++) {
IRouteNode iroute = iRoutes[i];
IRouteConfig fixConfig = config;
if(iroute.path!=config.uri.path){
fixConfig = IRouteConfig(uri: Uri.parse(iroute.path));
}
Page? page;
if (iroute is NotFindNode) {
page = widget.notFindPageBuilder(context, config);
} else if (iroute is CellIRoute) {
Widget scope = NavigatorScope(
node: iroute,
onPopPage: widget.onPopPage,
configs: widget.configs,
notFindPageBuilder: widget.notFindPageBuilder,
);
page = iroute.createCellPage(context, fixConfig, scope);
} else {
page = iroute.createPage(context, fixConfig);
}
if (page != null) {
result.add(page);
}
if (iroute is CellIRoute) {
break;
}
}
}
return result;
}
}

View File

@@ -3,11 +3,32 @@ import '../router/app_router_delegate.dart';
import 'app_navigation_rail.dart'; import 'app_navigation_rail.dart';
import 'app_top_bar/app_top_bar.dart'; import 'app_top_bar/app_top_bar.dart';
class AppNavigation extends StatelessWidget { class AppNavigation extends StatefulWidget {
const AppNavigation({super.key}); 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print('=======AppNavigation#build===============');
double px1 = 1/View.of(context).devicePixelRatio; double px1 = 1/View.of(context).devicePixelRatio;
return Scaffold( return Scaffold(
body: Row( body: Row(
@@ -19,10 +40,7 @@ class AppNavigation extends StatelessWidget {
const AppTopBar(), const AppTopBar(),
Divider(height: px1,), Divider(height: px1,),
Expanded( Expanded(
child: Router( child: widget.navigator,
routerDelegate: router,
backButtonDispatcher: RootBackButtonDispatcher(),
),
), ),
], ],
), ),

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:iroute/components/components.dart'; import 'package:iroute/components/components.dart';
import '../router/app_router_delegate.dart'; import '../router/app_router_delegate.dart';
import '../router/iroute_config.dart'; import '../router/iroute_config.dart';
import '../router/routes.dart';
class AppNavigationRail extends StatefulWidget { class AppNavigationRail extends StatefulWidget {
const AppNavigationRail({super.key}); const AppNavigationRail({super.key});
@@ -11,13 +12,6 @@ class AppNavigationRail extends StatefulWidget {
} }
class _AppNavigationRailState extends State<AppNavigationRail> { 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 @override
void initState() { 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 { int? get activeIndex {
String path = router.path; String path = router.path;
RegExpMatch? match = _segReg.firstMatch(path); RegExpMatch? match = _segReg.firstMatch(path);
if (match == null) return null; if (match == null) return null;
String? target = match.group(0); 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; if (index == -1) return null;
return index; return index;
} }

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:iroute/components/components.dart'; import 'package:iroute/components/components.dart';
import '../../router/app_router_delegate.dart'; import '../../router/app_router_delegate.dart';
import '../../router/routes.dart';
import '../../router/views/route_back_indicator.dart'; import '../../router/views/route_back_indicator.dart';
import 'app_router_editor.dart'; import 'app_router_editor.dart';
import 'history_view_icon.dart'; import 'history_view_icon.dart';
@@ -54,16 +55,6 @@ class RouterIndicator extends StatefulWidget {
State<RouterIndicator> createState() => _RouterIndicatorState(); State<RouterIndicator> createState() => _RouterIndicatorState();
} }
Map<String, String> kRouteLabelMap = {
'/color': '颜色板',
'/color/add': '添加颜色',
'/color/detail': '颜色详情',
'/counter': '计数器',
'/sort': '可视化排序算法',
'/sort/settings': '排序配置',
'/user': '我的',
'/settings': '系统设置',
};
class _RouterIndicatorState extends State<RouterIndicator> { class _RouterIndicatorState extends State<RouterIndicator> {
@override @override
@@ -107,7 +98,9 @@ class _RouterIndicatorState extends State<RouterIndicator> {
for (String segment in uri.pathSegments) { for (String segment in uri.pathSegments) {
to += '/$segment'; to += '/$segment';
String label = kRouteLabelMap[to] ?? '未知路由'; 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; return result;
} }

View File

@@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:iroute/components/components.dart'; import 'package:iroute/components/components.dart';
import '../../router/app_router_delegate.dart'; import '../../router/app_router_delegate.dart';
import '../../router/iroute.dart'; import '../../router/routes.dart';
import '../../router/iroute_config.dart'; import '../../router/iroute_config.dart';
import 'app_top_bar.dart'; import 'app_top_bar.dart';

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'navigation/router/app_router_delegate.dart';
import '../pages/sort/provider/state.dart'; import '../pages/sort/provider/state.dart';
import 'navigation/transition/fade_page_transitions_builder.dart'; import 'navigation/transition/fade_page_transitions_builder.dart';
import 'navigation/views/app_navigation.dart'; import 'navigation/views/app_navigation.dart';
@@ -12,7 +13,8 @@ class UnitApp extends StatelessWidget {
return SortStateScope( return SortStateScope(
notifier: SortState(), notifier: SortState(),
child: MaterialApp( child: MaterialApp.router(
routerDelegate: router,
theme: ThemeData( theme: ThemeData(
fontFamily: "宋体", fontFamily: "宋体",
scaffoldBackgroundColor: Colors.white, scaffoldBackgroundColor: Colors.white,
@@ -34,7 +36,7 @@ class UnitApp extends StatelessWidget {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
))), ))),
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
home: AppNavigation() // home: AppNavigation()
), ),
); );
} }

View File

@@ -17,6 +17,18 @@ class _ColorPageState extends State<ColorPage> {
Colors.pinkAccent, Colors.purpleAccent, Colors.indigoAccent, Colors.amberAccent, Colors.cyanAccent, Colors.pinkAccent, Colors.purpleAccent, Colors.indigoAccent, Colors.amberAccent, Colors.cyanAccent,
]; ];
@override
void initState() {
print('======_ColorPageState#initState==============');
super.initState();
}
@override
void dispose() {
print('======_ColorPageState#dispose==============');
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@@ -38,12 +50,12 @@ class _ColorPageState extends State<ColorPage> {
void _selectColor(Color color){ void _selectColor(Color color){
// String value = color.value.toRadixString(16); // String value = color.value.toRadixString(16);
// router.path = '/color/detail?color=$value'; // router.path = '/color/detail?color=$value';
router.changePath('/color/detail_error',extra: color); router.changePath('/app/color/detail',extra: color);
} }
void _toAddPage() async { void _toAddPage() async {
Color? color = await router.changePath('/color/add',forResult: true,recordHistory: false); Color? color = await router.changePath('/app/color/add',forResult: true,recordHistory: false);
if (color != null) { if (color != null) {
setState(() { setState(() {
_colors.add(color); _colors.add(color);

View File

@@ -10,6 +10,18 @@ class CounterPage extends StatefulWidget {
class _CounterPageState extends State<CounterPage> { class _CounterPageState extends State<CounterPage> {
int _counter = 0; int _counter = 0;
@override
void initState() {
print('======_CounterPageState#initState==============');
super.initState();
}
@override
void dispose() {
print('======_CounterPageState#dispose==============');
super.dispose();
}
void _incrementCounter() { void _incrementCounter() {
setState(() { setState(() {
_counter++; _counter++;

View File

@@ -0,0 +1,24 @@
import 'package:flutter/material.dart';
import '../../app/navigation/router/app_router_delegate.dart';
class LoginPage extends StatelessWidget {
const LoginPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Login Page',style: TextStyle(fontSize: 24),),
const SizedBox(height: 20,),
ElevatedButton(onPressed: (){
router.changePath('/app/color');
}, child: Text('点击进入'))
],
),
),
);
}
}

View File

@@ -38,26 +38,27 @@ class _SortSettingsState extends State<SortSettings> {
backgroundColor: Colors.white, backgroundColor: Colors.white,
appBar: AppBar( appBar: AppBar(
backgroundColor: Colors.white, backgroundColor: Colors.white,
leading: Align( automaticallyImplyLeading: false,
child: MouseRegion( // leading: Align(
cursor: SystemMouseCursors.click, // child: MouseRegion(
child: GestureDetector( // cursor: SystemMouseCursors.click,
onTap: (){ // child: GestureDetector(
Navigator.of(context).pop(); // onTap: (){
}, // Navigator.of(context).pop();
child: Container( // },
width: 28, // child: Container(
height: 28, // width: 28,
margin: EdgeInsets.only(right: 8,left: 8), // height: 28,
alignment: Alignment.center, // margin: EdgeInsets.only(right: 8,left: 8),
decoration: BoxDecoration( // alignment: Alignment.center,
color: Color(0xffE3E5E7), // decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6) // color: Color(0xffE3E5E7),
), // borderRadius: BorderRadius.circular(6)
child: Icon(Icons.arrow_back_ios_new,size: 18,)), // ),
), // child: Icon(Icons.arrow_back_ios_new,size: 18,)),
), // ),
), // ),
// ),
// leading: BackButton(), // leading: BackButton(),
actions: [ actions: [
Padding( Padding(

View File

@@ -2,6 +2,7 @@ import 'dart:ffi';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:iroute/v9/app/navigation/router/iroute_config.dart';
import '../player/sort_player.dart'; import '../player/sort_player.dart';
import '../../../../app/navigation/router/app_router_delegate.dart'; import '../../../../app/navigation/router/app_router_delegate.dart';
import '../settings/sort_setting.dart'; import '../settings/sort_setting.dart';
@@ -10,14 +11,10 @@ import 'sort_button.dart';
import '../../functions.dart'; import '../../functions.dart';
import '../../provider/state.dart'; import '../../provider/state.dart';
class SortPage extends StatefulWidget { class SortNavigation extends StatelessWidget {
const SortPage({super.key}); final Widget navigator;
const SortNavigation({super.key, required this.navigator});
@override
State<SortPage> createState() => _SortPageState();
}
class _SortPageState extends State<SortPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Material( return Material(
@@ -31,7 +28,7 @@ class _SortPageState extends State<SortPage> {
width: 1, width: 1,
), ),
Expanded( Expanded(
child: SortNavigatorScope(), child: navigator,
) )
], ],
), ),
@@ -68,7 +65,7 @@ class SortRailPanel extends StatelessWidget {
cursor: SystemMouseCursors.click, cursor: SystemMouseCursors.click,
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
router.changePath('/sort/settings'); router.changePath('/app/sort/settings',style: RouteStyle.push);
}, },
child: const Icon( child: const Icon(
CupertinoIcons.settings, CupertinoIcons.settings,
@@ -87,7 +84,7 @@ class SortRailPanel extends StatelessWidget {
options: sortNameMap.values.toList(), options: sortNameMap.values.toList(),
onSelected: (name) { onSelected: (name) {
state.selectName(name); state.selectName(name);
router.changePath('/sort'); router.changePath('/sort/player');
}, },
), ),
), ),