From 5396712cf9d6b5336775d5752bbcf2dd3d6412bd Mon Sep 17 00:00:00 2001 From: toly <1981462002@qq.com> Date: Sat, 11 Nov 2023 11:37:41 +0800 Subject: [PATCH] v9 --- lib/main.dart | 2 +- lib/v7/pages/color/color_page.dart | 2 +- lib/v8/pages/color/color_page.dart | 2 +- .../router/app_router_delegate.dart | 54 ++++++--- lib/v9/app/navigation/router/iroute.dart | 55 +++++++-- lib/v9/app/navigation/router/routes.dart | 70 ++++++++--- .../router/views/navigator_scope.dart | 109 ++++++++++++++++++ .../app/navigation/views/app_navigation.dart | 30 ++++- .../navigation/views/app_navigation_rail.dart | 12 +- .../views/app_top_bar/app_top_bar.dart | 15 +-- .../views/app_top_bar/history_view_icon.dart | 2 +- lib/v9/app/unit_app.dart | 6 +- lib/v9/pages/color/color_page.dart | 16 ++- lib/v9/pages/counter/counter_page.dart | 12 ++ lib/v9/pages/login/login.dart | 24 ++++ .../sort/views/settings/sort_setting.dart | 41 +++---- .../pages/sort/views/sort_page/sort_page.dart | 17 ++- 17 files changed, 368 insertions(+), 101 deletions(-) create mode 100644 lib/v9/app/navigation/router/views/navigator_scope.dart create mode 100644 lib/v9/pages/login/login.dart diff --git a/lib/main.dart b/lib/main.dart index 4d91ffb..5c312c8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:window_manager/window_manager.dart'; -import 'v8/app.dart'; +import 'v9/app.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); diff --git a/lib/v7/pages/color/color_page.dart b/lib/v7/pages/color/color_page.dart index 39bcc1b..8fdbe13 100644 --- a/lib/v7/pages/color/color_page.dart +++ b/lib/v7/pages/color/color_page.dart @@ -38,7 +38,7 @@ class _ColorPageState extends State { void _selectColor(Color color){ // String value = color.value.toRadixString(16); // router.path = '/color/detail?color=$value'; - router.changePath('/color/detail_error',extra: color); + router.changePath('/color/detail',extra: color); } diff --git a/lib/v8/pages/color/color_page.dart b/lib/v8/pages/color/color_page.dart index 39bcc1b..8fdbe13 100644 --- a/lib/v8/pages/color/color_page.dart +++ b/lib/v8/pages/color/color_page.dart @@ -38,7 +38,7 @@ class _ColorPageState extends State { void _selectColor(Color color){ // String value = color.value.toRadixString(16); // router.path = '/color/detail?color=$value'; - router.changePath('/color/detail_error',extra: color); + router.changePath('/color/detail',extra: color); } diff --git a/lib/v9/app/navigation/router/app_router_delegate.dart b/lib/v9/app/navigation/router/app_router_delegate.dart index b439c4e..1ab520a 100644 --- a/lib/v9/app/navigation/router/app_router_delegate.dart +++ b/lib/v9/app/navigation/router/app_router_delegate.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:iroute/v9/app/navigation/router/views/navigator_scope.dart'; import 'iroute.dart'; import 'iroute_config.dart'; import 'route_history_manager.dart'; @@ -7,11 +8,12 @@ import 'routes.dart'; import 'views/not_find_view.dart'; AppRouterDelegate router = AppRouterDelegate( - initial: IRouteConfig(uri: Uri.parse('/color')), -); + initial: IRouteConfig( + uri: Uri.parse('/app/color'), + ), + node: appRoute); class AppRouterDelegate extends RouterDelegate with ChangeNotifier { - /// 核心数据,路由配置数据列表 final List _configs = []; @@ -21,8 +23,11 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { final IRoutePageBuilder? notFindPageBuilder; + final IRouteNode node; + AppRouterDelegate({ this.notFindPageBuilder, + required this.node, required IRouteConfig initial, }) { _configs.add(initial); @@ -57,7 +62,8 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { // final List _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> _completerMap = {}; @@ -80,7 +86,7 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { } } - void _handleChangeStyle(IRouteConfig config){ + void _handleChangeStyle(IRouteConfig config) { switch (config.routeStyle) { case RouteStyle.push: if (_configs.contains(config)) { @@ -89,9 +95,10 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { _configs.add(config); break; case RouteStyle.replace: - List liveRoutes = _configs.where((e) => e.keepAlive&&e!=config).toList(); + List liveRoutes = + _configs.where((e) => e.keepAlive && e != config).toList(); _configs.clear(); - _configs.addAll([...liveRoutes,config]); + _configs.addAll([...liveRoutes, config]); break; } } @@ -101,7 +108,7 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { bool forResult = false, Object? extra, bool keepAlive = false, - bool recordHistory = true, + bool recordHistory = false, RouteStyle style = RouteStyle.replace, }) { return changeRoute(IRouteConfig( @@ -116,15 +123,29 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { @override Widget build(BuildContext context) { - return Navigator( + return NavigatorScope( + node: node, 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 _buildPages(BuildContext context, List configs) { IRouteConfig top = configs.last; - List bottoms = _configs.sublist(0,_configs.length-1).toList(); + List bottoms = + _configs.sublist(0, _configs.length - 1).toList(); List pages = []; List topPages = _buildPageByPathFromTree(context, top); pages = _buildLivePageByPathList(context, bottoms, top, topPages); @@ -145,8 +166,10 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { pages.addAll(_buildPageByPathFromTree(context, path)); } } + /// 去除和 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; } @@ -161,14 +184,15 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { config = config.copyWith(path: iroute.path); Page? page; if (iroute is NotFindNode) { - page = (notFindPageBuilder ?? _defaultNotFindPageBuilder)(context, config); + page = (notFindPageBuilder ?? _defaultNotFindPageBuilder)( + context, config); } else { page = iroute.createPage(context, config); } if (page != null) { result.add(page); } - if(iroute is CellIRoute){ + if (iroute is CellIRoute) { break; } } @@ -199,7 +223,7 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { _completerMap.remove(path); } - if (_configs.isNotEmpty) { + if (_configs.length > 1) { _configs.removeLast(); notifyListeners(); } else { diff --git a/lib/v9/app/navigation/router/iroute.dart b/lib/v9/app/navigation/router/iroute.dart index 8e1de0f..dffa34b 100644 --- a/lib/v9/app/navigation/router/iroute.dart +++ b/lib/v9/app/navigation/router/iroute.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:iroute/v9/app/navigation/router/views/navigator_scope.dart'; import 'iroute_config.dart'; @@ -7,6 +8,8 @@ typedef IRoutePageBuilder = Page? Function( IRouteConfig data, ); + + typedef IRouteWidgetBuilder = Widget? Function( BuildContext context, IRouteConfig data, @@ -26,7 +29,15 @@ abstract class IRouteNode { List find( 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 findNodes( @@ -43,6 +54,7 @@ abstract class IRouteNode { String target = parts[deep]; if (node.children.isNotEmpty) { target = prefix + target; + List nodes = node.children.where((e) => e.path == target).toList(); 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({ + required this.cellBuilder, + this.pageBuilder, required super.path, - super.pageBuilder, - super.children, - super.widget, + required super.children, }); -} -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, + ); + } +} \ No newline at end of file diff --git a/lib/v9/app/navigation/router/routes.dart b/lib/v9/app/navigation/router/routes.dart index da6fb72..546490c 100644 --- a/lib/v9/app/navigation/router/routes.dart +++ b/lib/v9/app/navigation/router/routes.dart @@ -1,6 +1,10 @@ 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 'iroute_config.dart'; +import '../views/app_navigation.dart'; import 'iroute.dart'; import '../../../pages/color/color_add_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/settings/sort_setting.dart'; -IRoute rootRoute = const IRoute( - path: 'root', +CellIRoute appRoute = CellIRoute( + cellBuilder: (_, __, navigator) => AppNavigation( + navigator: navigator, + ), + path: '/app', children: [ - IRoute( - path: '/color', + IRoute( + path: '/app/color', widget: ColorPage(), children: [ - IRoute(path: '/color/detail', widgetBuilder: _buildColorDetail), - IRoute(path: '/color/add', widget: ColorAddPage()), + IRoute(path: '/app/color/detail', widgetBuilder: _buildColorDetail), + IRoute(path: '/app/color/add', widget: ColorAddPage()), ], ), - IRoute(path: '/counter', widget: CounterPage()), + const IRoute(path: '/app/counter', widget: CounterPage()), CellIRoute( - path: '/sort', - widget: SortPage(), + cellBuilder: (_, __, navigator) => SortNavigation(navigator: navigator), + // pageBuilder: (_,config,child)=> NoTransitionPage( + // child: child, + // key: config.pageKey + // ), + path: '/app/sort', children: [ - IRoute( - path: '/sort/settings', + const IRoute( + path: '/app/sort/settings', widget: SortSettings(), ), - IRoute( - path: '/sort/player', + const IRoute( + path: '/app/sort/player', widget: SortPlayer(), ), ], ), - IRoute(path: '/user', widget: UserPage()), - IRoute(path: '/settings', widget: SettingPage()), + const IRoute(path: '/app/user', widget: UserPage()), + 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) { final Map queryParams = data.uri.queryParameters; String? selectedColor = queryParams['color']; @@ -53,3 +72,24 @@ Widget? _buildColorDetail(BuildContext context, IRouteConfig data) { } return ColorDetailPage(color: color); } + +Map 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 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'), +]; diff --git a/lib/v9/app/navigation/router/views/navigator_scope.dart b/lib/v9/app/navigation/router/views/navigator_scope.dart new file mode 100644 index 0000000..be7b1d8 --- /dev/null +++ b/lib/v9/app/navigation/router/views/navigator_scope.dart @@ -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 configs; + final IRoutePageBuilder notFindPageBuilder; + + const NavigatorScope({ + super.key, + required this.node, + required this.onPopPage, + required this.configs, + required this.notFindPageBuilder, + }); + + @override + State createState() => _NavigatorScopeState(); +} + +class _NavigatorScopeState extends State { + @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 _buildPages(BuildContext context, List configs) { + IRouteConfig top = configs.last; + List bottoms = + configs.sublist(0, configs.length - 1).toList(); + List pages = []; + List topPages = _buildPageByPathFromTree(context, top); + pages = _buildLivePageByPathList(context, bottoms, top, topPages); + pages.addAll(topPages); + return pages; + } + + List _buildLivePageByPathList( + BuildContext context, + List paths, + IRouteConfig curConfig, + List curPages, + ) { + List 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 _buildPageByPathFromTree( + BuildContext context, IRouteConfig config) { + List result = []; + List 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; + } +} diff --git a/lib/v9/app/navigation/views/app_navigation.dart b/lib/v9/app/navigation/views/app_navigation.dart index 5abca82..14d3ea0 100644 --- a/lib/v9/app/navigation/views/app_navigation.dart +++ b/lib/v9/app/navigation/views/app_navigation.dart @@ -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 createState() => _AppNavigationState(); +} + +class _AppNavigationState extends State { + + @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, ), ], ), diff --git a/lib/v9/app/navigation/views/app_navigation_rail.dart b/lib/v9/app/navigation/views/app_navigation_rail.dart index 50287ff..09b54e8 100644 --- a/lib/v9/app/navigation/views/app_navigation_rail.dart +++ b/lib/v9/app/navigation/views/app_navigation_rail.dart @@ -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 { - final List 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 { ); } - 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; } diff --git a/lib/v9/app/navigation/views/app_top_bar/app_top_bar.dart b/lib/v9/app/navigation/views/app_top_bar/app_top_bar.dart index 072a838..150ac6b 100644 --- a/lib/v9/app/navigation/views/app_top_bar/app_top_bar.dart +++ b/lib/v9/app/navigation/views/app_top_bar/app_top_bar.dart @@ -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 createState() => _RouterIndicatorState(); } -Map kRouteLabelMap = { - '/color': '颜色板', - '/color/add': '添加颜色', - '/color/detail': '颜色详情', - '/counter': '计数器', - '/sort': '可视化排序算法', - '/sort/settings': '排序配置', - '/user': '我的', - '/settings': '系统设置', -}; class _RouterIndicatorState extends State { @override @@ -107,7 +98,9 @@ class _RouterIndicatorState extends State { 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; } diff --git a/lib/v9/app/navigation/views/app_top_bar/history_view_icon.dart b/lib/v9/app/navigation/views/app_top_bar/history_view_icon.dart index 3390a49..e2ad492 100644 --- a/lib/v9/app/navigation/views/app_top_bar/history_view_icon.dart +++ b/lib/v9/app/navigation/views/app_top_bar/history_view_icon.dart @@ -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'; diff --git a/lib/v9/app/unit_app.dart b/lib/v9/app/unit_app.dart index 33f59bf..de14a7e 100644 --- a/lib/v9/app/unit_app.dart +++ b/lib/v9/app/unit_app.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'navigation/router/app_router_delegate.dart'; import '../pages/sort/provider/state.dart'; import 'navigation/transition/fade_page_transitions_builder.dart'; import 'navigation/views/app_navigation.dart'; @@ -12,7 +13,8 @@ class UnitApp extends StatelessWidget { return SortStateScope( notifier: SortState(), - child: MaterialApp( + child: MaterialApp.router( + routerDelegate: router, theme: ThemeData( fontFamily: "宋体", scaffoldBackgroundColor: Colors.white, @@ -34,7 +36,7 @@ class UnitApp extends StatelessWidget { fontWeight: FontWeight.bold, ))), debugShowCheckedModeBanner: false, - home: AppNavigation() + // home: AppNavigation() ), ); } diff --git a/lib/v9/pages/color/color_page.dart b/lib/v9/pages/color/color_page.dart index 39bcc1b..644005e 100644 --- a/lib/v9/pages/color/color_page.dart +++ b/lib/v9/pages/color/color_page.dart @@ -17,6 +17,18 @@ class _ColorPageState extends State { 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 Widget build(BuildContext context) { return Scaffold( @@ -38,12 +50,12 @@ class _ColorPageState extends State { void _selectColor(Color color){ // String value = color.value.toRadixString(16); // router.path = '/color/detail?color=$value'; - router.changePath('/color/detail_error',extra: color); + router.changePath('/app/color/detail',extra: color); } 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) { setState(() { _colors.add(color); diff --git a/lib/v9/pages/counter/counter_page.dart b/lib/v9/pages/counter/counter_page.dart index b5b2e17..b74a199 100644 --- a/lib/v9/pages/counter/counter_page.dart +++ b/lib/v9/pages/counter/counter_page.dart @@ -10,6 +10,18 @@ class CounterPage extends StatefulWidget { class _CounterPageState extends State { int _counter = 0; + @override + void initState() { + print('======_CounterPageState#initState=============='); + super.initState(); + } + + @override + void dispose() { + print('======_CounterPageState#dispose=============='); + super.dispose(); + } + void _incrementCounter() { setState(() { _counter++; diff --git a/lib/v9/pages/login/login.dart b/lib/v9/pages/login/login.dart new file mode 100644 index 0000000..af1568a --- /dev/null +++ b/lib/v9/pages/login/login.dart @@ -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('点击进入')) + ], + ), + ), + ); + } +} diff --git a/lib/v9/pages/sort/views/settings/sort_setting.dart b/lib/v9/pages/sort/views/settings/sort_setting.dart index 654d549..84f5f52 100644 --- a/lib/v9/pages/sort/views/settings/sort_setting.dart +++ b/lib/v9/pages/sort/views/settings/sort_setting.dart @@ -38,26 +38,27 @@ class _SortSettingsState extends State { backgroundColor: Colors.white, appBar: AppBar( backgroundColor: Colors.white, - leading: Align( - child: MouseRegion( - cursor: SystemMouseCursors.click, - child: GestureDetector( - onTap: (){ - Navigator.of(context).pop(); - }, - child: Container( - width: 28, - height: 28, - margin: EdgeInsets.only(right: 8,left: 8), - alignment: Alignment.center, - decoration: BoxDecoration( - color: Color(0xffE3E5E7), - borderRadius: BorderRadius.circular(6) - ), - child: Icon(Icons.arrow_back_ios_new,size: 18,)), - ), - ), - ), + automaticallyImplyLeading: false, + // leading: Align( + // child: MouseRegion( + // cursor: SystemMouseCursors.click, + // child: GestureDetector( + // onTap: (){ + // Navigator.of(context).pop(); + // }, + // child: Container( + // width: 28, + // height: 28, + // margin: EdgeInsets.only(right: 8,left: 8), + // alignment: Alignment.center, + // decoration: BoxDecoration( + // color: Color(0xffE3E5E7), + // borderRadius: BorderRadius.circular(6) + // ), + // child: Icon(Icons.arrow_back_ios_new,size: 18,)), + // ), + // ), + // ), // leading: BackButton(), actions: [ Padding( diff --git a/lib/v9/pages/sort/views/sort_page/sort_page.dart b/lib/v9/pages/sort/views/sort_page/sort_page.dart index 7c11b9a..4091b44 100644 --- a/lib/v9/pages/sort/views/sort_page/sort_page.dart +++ b/lib/v9/pages/sort/views/sort_page/sort_page.dart @@ -2,6 +2,7 @@ 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'; @@ -10,14 +11,10 @@ import 'sort_button.dart'; import '../../functions.dart'; import '../../provider/state.dart'; -class SortPage extends StatefulWidget { - const SortPage({super.key}); +class SortNavigation extends StatelessWidget { + final Widget navigator; + const SortNavigation({super.key, required this.navigator}); - @override - State createState() => _SortPageState(); -} - -class _SortPageState extends State { @override Widget build(BuildContext context) { return Material( @@ -31,7 +28,7 @@ class _SortPageState extends State { width: 1, ), Expanded( - child: SortNavigatorScope(), + child: navigator, ) ], ), @@ -68,7 +65,7 @@ class SortRailPanel extends StatelessWidget { cursor: SystemMouseCursors.click, child: GestureDetector( onTap: () { - router.changePath('/sort/settings'); + router.changePath('/app/sort/settings',style: RouteStyle.push); }, child: const Icon( CupertinoIcons.settings, @@ -87,7 +84,7 @@ class SortRailPanel extends StatelessWidget { options: sortNameMap.values.toList(), onSelected: (name) { state.selectName(name); - router.changePath('/sort'); + router.changePath('/sort/player'); }, ), ),