From d518b3c58a68a74fb30313fdd31a74640b541faf Mon Sep 17 00:00:00 2001 From: toly <1981462002@qq.com> Date: Thu, 19 Oct 2023 21:51:44 +0800 Subject: [PATCH] 13-04 --- lib/12/01/pages/page_a.dart | 4 + lib/12/01/pages/page_c.dart | 4 +- lib/13/01/pages/app/app_router_delegate.dart | 6 +- lib/13/01/pages/page_a.dart | 4 + lib/13/01/pages/page_b.dart | 5 +- lib/13/01/pages/page_c.dart | 5 + lib/13/02/main.dart | 14 ++ lib/13/02/pages/app/app.dart | 30 +++ lib/13/02/pages/app/app_router_delegate.dart | 93 +++++++++ lib/13/02/pages/app/app_tool_bar.dart | 64 +++++++ lib/13/02/pages/home_page.dart | 30 +++ lib/13/02/pages/page_a.dart | 29 +++ lib/13/02/pages/page_b.dart | 30 +++ lib/13/02/pages/page_c.dart | 23 +++ .../app/navigation/app_router_delegate.dart | 114 +++++++++++ .../navigation/views/app_navigation_rail.dart | 53 ++++++ lib/13/03/app/unit_app.dart | 38 ++++ lib/13/03/main.dart | 7 +- lib/13/03/pages/color/color_page.dart | 52 +++++ lib/13/03/pages/counter/counter_page.dart | 43 +++++ lib/13/03/pages/empty/empty_page.dart | 30 +++ lib/13/03/pages/settings/settings_page.dart | 11 ++ lib/13/03/pages/user/user_page.dart | 11 ++ .../03/transition/fade_transition_page.dart | 53 ++++++ lib/13/03/transition/no_transition_page.dart | 47 +++++ lib/13/03_/main.dart | 13 ++ lib/13/{03 => 03_}/menus.dart | 0 lib/13/{03 => 03_}/pages/app/app.dart | 0 .../{03 => 03_}/pages/app/root_content.dart | 0 .../app/navigation/app_router_delegate.dart | 179 ++++++++++++++++++ lib/13/04/app/navigation/router/iroute.dart | 37 ++++ .../navigation/views/app_navigation_rail.dart | 50 +++++ lib/13/04/app/unit_app.dart | 38 ++++ lib/13/04/main.dart | 16 ++ lib/13/04/pages/color/color_add_page.dart | 67 +++++++ lib/13/04/pages/color/color_page.dart | 59 ++++++ lib/13/04/pages/counter/counter_page.dart | 43 +++++ lib/13/04/pages/empty/empty_page.dart | 30 +++ lib/13/04/pages/settings/settings_page.dart | 11 ++ lib/13/04/pages/user/user_page.dart | 11 ++ .../04/transition/fade_transition_page.dart | 53 ++++++ lib/13/04/transition/no_transition_page.dart | 47 +++++ lib/13/节点介绍.txt | 6 + test/parser/main.dart | 46 +++++ 44 files changed, 1496 insertions(+), 10 deletions(-) create mode 100644 lib/13/02/main.dart create mode 100644 lib/13/02/pages/app/app.dart create mode 100644 lib/13/02/pages/app/app_router_delegate.dart create mode 100644 lib/13/02/pages/app/app_tool_bar.dart create mode 100644 lib/13/02/pages/home_page.dart create mode 100644 lib/13/02/pages/page_a.dart create mode 100644 lib/13/02/pages/page_b.dart create mode 100644 lib/13/02/pages/page_c.dart create mode 100644 lib/13/03/app/navigation/app_router_delegate.dart create mode 100644 lib/13/03/app/navigation/views/app_navigation_rail.dart create mode 100644 lib/13/03/app/unit_app.dart create mode 100644 lib/13/03/pages/color/color_page.dart create mode 100644 lib/13/03/pages/counter/counter_page.dart create mode 100644 lib/13/03/pages/empty/empty_page.dart create mode 100644 lib/13/03/pages/settings/settings_page.dart create mode 100644 lib/13/03/pages/user/user_page.dart create mode 100644 lib/13/03/transition/fade_transition_page.dart create mode 100644 lib/13/03/transition/no_transition_page.dart create mode 100644 lib/13/03_/main.dart rename lib/13/{03 => 03_}/menus.dart (100%) rename lib/13/{03 => 03_}/pages/app/app.dart (100%) rename lib/13/{03 => 03_}/pages/app/root_content.dart (100%) create mode 100644 lib/13/04/app/navigation/app_router_delegate.dart create mode 100644 lib/13/04/app/navigation/router/iroute.dart create mode 100644 lib/13/04/app/navigation/views/app_navigation_rail.dart create mode 100644 lib/13/04/app/unit_app.dart create mode 100644 lib/13/04/main.dart create mode 100644 lib/13/04/pages/color/color_add_page.dart create mode 100644 lib/13/04/pages/color/color_page.dart create mode 100644 lib/13/04/pages/counter/counter_page.dart create mode 100644 lib/13/04/pages/empty/empty_page.dart create mode 100644 lib/13/04/pages/settings/settings_page.dart create mode 100644 lib/13/04/pages/user/user_page.dart create mode 100644 lib/13/04/transition/fade_transition_page.dart create mode 100644 lib/13/04/transition/no_transition_page.dart create mode 100644 lib/13/节点介绍.txt create mode 100644 test/parser/main.dart diff --git a/lib/12/01/pages/page_a.dart b/lib/12/01/pages/page_a.dart index ceca6a6..0914954 100644 --- a/lib/12/01/pages/page_a.dart +++ b/lib/12/01/pages/page_a.dart @@ -13,6 +13,7 @@ class PageA extends StatelessWidget { appBar: AppBar( title: const Text('A 界面'), backgroundColor: bgColor, + leading: BackButton(onPressed: _pop), ), body: Center( child: ElevatedButton( @@ -26,4 +27,7 @@ class PageA extends StatelessWidget { router.value = ['/', 'a', 'b']; } + void _pop() { + router.value = List.of(router.value)..removeLast(); + } } diff --git a/lib/12/01/pages/page_c.dart b/lib/12/01/pages/page_c.dart index e37cdbe..7cd165b 100644 --- a/lib/12/01/pages/page_c.dart +++ b/lib/12/01/pages/page_c.dart @@ -14,9 +14,7 @@ class PageC extends StatelessWidget { appBar: AppBar( title: const Text('C 界面'), backgroundColor: bgColor, - leading: BackButton( - onPressed: _pop, - ), + leading: BackButton(onPressed: _pop), ), body: Center( child: Text('到达终点'), diff --git a/lib/13/01/pages/app/app_router_delegate.dart b/lib/13/01/pages/app/app_router_delegate.dart index e6ffd43..6902e2e 100644 --- a/lib/13/01/pages/app/app_router_delegate.dart +++ b/lib/13/01/pages/app/app_router_delegate.dart @@ -7,7 +7,7 @@ import '../page_b.dart'; import '../page_c.dart'; import '../home_page.dart'; -class AppRouterDelegate extends RouterDelegate with ChangeNotifier{ +class AppRouterDelegate extends RouterDelegate with ChangeNotifier{ List _value = ['/']; @@ -35,13 +35,11 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier{ @override Future popRoute() async{ - print('================'); + print('=======popRoute========='); return true; } bool _onPopPage(Route route, result) { - _value = List.of(_value)..removeLast(); - notifyListeners(); return route.didPop(result); } diff --git a/lib/13/01/pages/page_a.dart b/lib/13/01/pages/page_a.dart index 6e454bc..0ab03bf 100644 --- a/lib/13/01/pages/page_a.dart +++ b/lib/13/01/pages/page_a.dart @@ -13,6 +13,7 @@ class PageA extends StatelessWidget { appBar: AppBar( title: const Text('A 界面'), backgroundColor: bgColor, + leading: BackButton(onPressed: _pop), ), body: Center( child: ElevatedButton( @@ -26,4 +27,7 @@ class PageA extends StatelessWidget { router.value = ['/', 'a', 'b']; } + void _pop() { + router.value = List.of(router.value)..removeLast(); + } } diff --git a/lib/13/01/pages/page_b.dart b/lib/13/01/pages/page_b.dart index 3366c2a..2cc386f 100644 --- a/lib/13/01/pages/page_b.dart +++ b/lib/13/01/pages/page_b.dart @@ -15,7 +15,7 @@ class PageB extends StatelessWidget { appBar: AppBar( title: const Text('B 界面'), backgroundColor: bgColor, - + leading: BackButton(onPressed: _pop), ), body: Center( child: ElevatedButton( @@ -29,4 +29,7 @@ class PageB extends StatelessWidget { router.value = ['/','a','b','c']; } + void _pop() { + router.value = List.of(router.value)..removeLast(); + } } \ No newline at end of file diff --git a/lib/13/01/pages/page_c.dart b/lib/13/01/pages/page_c.dart index b912861..4d1e5ed 100644 --- a/lib/13/01/pages/page_c.dart +++ b/lib/13/01/pages/page_c.dart @@ -14,9 +14,14 @@ class PageC extends StatelessWidget { appBar: AppBar( title: const Text('C 界面'), backgroundColor: bgColor, + leading: BackButton(onPressed: _pop), ), body: Center( child: Text('到达终点'), )); } + + void _pop() { + router.value = List.of(router.value)..removeLast(); + } } diff --git a/lib/13/02/main.dart b/lib/13/02/main.dart new file mode 100644 index 0000000..dc14a42 --- /dev/null +++ b/lib/13/02/main.dart @@ -0,0 +1,14 @@ +import 'package:flutter/material.dart'; +import 'pages/app/app.dart'; +import 'pages/app/app_router_delegate.dart'; + + +AppRouterDelegate router = AppRouterDelegate(); + +void main() { + runApp(const App()); +} + + + + diff --git a/lib/13/02/pages/app/app.dart b/lib/13/02/pages/app/app.dart new file mode 100644 index 0000000..df39496 --- /dev/null +++ b/lib/13/02/pages/app/app.dart @@ -0,0 +1,30 @@ +import 'package:flutter/material.dart'; + +import '../../main.dart'; +import 'app_tool_bar.dart'; + +class App extends StatelessWidget { + const App({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp( + theme: ThemeData( + appBarTheme: const AppBarTheme( + elevation: 0, + iconTheme: IconThemeData(color: Colors.black), + titleTextStyle: TextStyle( + color: Colors.black, + fontSize: 18, + fontWeight: FontWeight.bold, + ))), + debugShowCheckedModeBanner: false, + home: Scaffold( + appBar: const AppToolBar(), + body: Router( + routerDelegate: router, + backButtonDispatcher: RootBackButtonDispatcher(), + ), + )); + } +} diff --git a/lib/13/02/pages/app/app_router_delegate.dart b/lib/13/02/pages/app/app_router_delegate.dart new file mode 100644 index 0000000..b84f1dc --- /dev/null +++ b/lib/13/02/pages/app/app_router_delegate.dart @@ -0,0 +1,93 @@ +import 'dart:ffi'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import '../page_a.dart'; +import '../page_b.dart'; +import '../page_c.dart'; +import '../home_page.dart'; + +class AppRouterDelegate extends RouterDelegate with ChangeNotifier{ + + List _value = ['/']; + + List get value => _value; + + set value(List value){ + _value = value; + notifyListeners(); + } + + @override + Widget build(BuildContext context) { + return Navigator( + onPopPage: _onPopPage, + pages: _value.map((e) => _pageMap[e]!).toList(), + ); + } + + final Map _pageMap = const { + '/': MaterialPage(child: HomePage()), + 'a': MaterialPage(child: PageA()), + 'b': MaterialPage(child: PageB()), + 'c': MaterialPage(child: PageC()), + }; + + @override + Future popRoute() async{ + print('=======popRoute========='); + return true; + } + + bool _onPopPage(Route route, result) { + value = List.of(_value)..removeLast(); + return route.didPop(result); + } + + @override + Future setNewRoutePath(configuration) async{ + + } + +} + +// class AppRouterDelegate extends RouterDelegate with ChangeNotifier, PopNavigatorRouterDelegateMixin { +// +// List _value = ['/']; +// +// +// List get value => _value; +// +// set value(List value){ +// _value = value; +// notifyListeners(); +// } +// +// @override +// Widget build(BuildContext context) { +// return Navigator( +// onPopPage: _onPopPage, +// pages: _value.map((e) => _pageMap[e]!).toList(), +// ); +// } +// +// final Map _pageMap = const { +// '/': MaterialPage(child: HomePage()), +// 'a': MaterialPage(child: PageA()), +// 'b': MaterialPage(child: PageB()), +// 'c': MaterialPage(child: PageC()), +// }; +// +// bool _onPopPage(Route route, result) { +// _value = List.of(_value)..removeLast(); +// notifyListeners(); +// return route.didPop(result); +// } +// +// @override +// GlobalKey? navigatorKey = GlobalKey(); +// +// @override +// Future setNewRoutePath(String configuration) async{ +// } +// } \ No newline at end of file diff --git a/lib/13/02/pages/app/app_tool_bar.dart b/lib/13/02/pages/app/app_tool_bar.dart new file mode 100644 index 0000000..dc6eff8 --- /dev/null +++ b/lib/13/02/pages/app/app_tool_bar.dart @@ -0,0 +1,64 @@ +import 'package:flutter/material.dart'; +import '../../main.dart'; + +class AppToolBar extends StatefulWidget implements PreferredSizeWidget{ + const AppToolBar({super.key}); + + @override + State createState() => _AppToolBarState(); + + @override + Size get preferredSize => const Size.fromHeight(kToolbarHeight); +} + +class _AppToolBarState extends State { + + TextEditingController _ctrl = TextEditingController(); + + @override + void initState() { + super.initState(); + _changRoute(); + router.addListener(_changRoute); + } + + @override + void dispose() { + router.removeListener(_changRoute); + _ctrl.dispose(); + super.dispose(); + } + + void _changRoute() { + _ctrl.text= router.value.join(','); + } + + @override + Widget build(BuildContext context) { + + return AppBar( + backgroundColor: Colors.white, + elevation: 0, + title : TextField( + controller: _ctrl, + onSubmitted: _onSubmitted, + decoration: InputDecoration( //装饰 + filled: true, //填充 + fillColor: Color(0xffF3F6F9), //填充颜色 + constraints: BoxConstraints(maxHeight: 34), //约束信息 + contentPadding: EdgeInsets.only(top: -14,left: 10), + border: UnderlineInputBorder( //边线信息 + borderSide: BorderSide.none, + borderRadius: BorderRadius.all(Radius.circular(6)), + ), + hintText: "请输入路由", //提示字 + hintStyle: TextStyle(fontSize: 14) //提示字样式 + ), + ), + ); + } + + void _onSubmitted(String value) { + router.value = value.split(','); + } +} diff --git a/lib/13/02/pages/home_page.dart b/lib/13/02/pages/home_page.dart new file mode 100644 index 0000000..0c19d8d --- /dev/null +++ b/lib/13/02/pages/home_page.dart @@ -0,0 +1,30 @@ + +import 'package:flutter/material.dart'; + +import '../main.dart'; + + +class HomePage extends StatelessWidget { + const HomePage({super.key}); + + @override + Widget build(BuildContext context) { + const Color bgColor = Color(0xffCCFFCC); + + return Scaffold( + backgroundColor: bgColor, + appBar: AppBar( + title: const Text('主页起点'), + backgroundColor: bgColor, + ), + body: Center(child: ElevatedButton( + onPressed: () => toPageA(context), + child: const Text('Push A'), + ), + )); + } + + void toPageA(BuildContext context) { + router.value = ['/', 'a']; + } +} diff --git a/lib/13/02/pages/page_a.dart b/lib/13/02/pages/page_a.dart new file mode 100644 index 0000000..6e454bc --- /dev/null +++ b/lib/13/02/pages/page_a.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; +import '../main.dart'; + +class PageA extends StatelessWidget { + const PageA({super.key}); + + @override + Widget build(BuildContext context) { + const Color bgColor = Color(0xffCCFFFF); + + return Scaffold( + backgroundColor: bgColor, + appBar: AppBar( + title: const Text('A 界面'), + backgroundColor: bgColor, + ), + body: Center( + child: ElevatedButton( + onPressed: () => toPageB(context), + child: const Text('Push B'), + ), + )); + } + + void toPageB(BuildContext context) { + router.value = ['/', 'a', 'b']; + } + +} diff --git a/lib/13/02/pages/page_b.dart b/lib/13/02/pages/page_b.dart new file mode 100644 index 0000000..84d47f3 --- /dev/null +++ b/lib/13/02/pages/page_b.dart @@ -0,0 +1,30 @@ +import 'package:flutter/material.dart'; + +import '../main.dart'; + +class PageB extends StatelessWidget { + const PageB({super.key}); + + + @override + Widget build(BuildContext context) { + const Color bgColor = Color(0xffCCE5FF); + + return Scaffold( + backgroundColor: bgColor, + appBar: AppBar( + title: const Text('B 界面'), + backgroundColor: bgColor, + ), + body: Center( + child: ElevatedButton( + onPressed: () => toPageC(context), + child: const Text('Push C'), + ), + )); + } + + void toPageC(BuildContext context){ + router.value = ['/','a','b','c']; + } +} \ No newline at end of file diff --git a/lib/13/02/pages/page_c.dart b/lib/13/02/pages/page_c.dart new file mode 100644 index 0000000..f7d0823 --- /dev/null +++ b/lib/13/02/pages/page_c.dart @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; + +import '../main.dart'; + +class PageC extends StatelessWidget { + const PageC({super.key}); + + @override + Widget build(BuildContext context) { + const Color bgColor = Color(0xffFFE6CC); + + return Scaffold( + backgroundColor: bgColor, + appBar: AppBar( + title: const Text('C 界面'), + backgroundColor: bgColor, + ), + body: Center( + child: Text('到达终点'), + )); + } + +} diff --git a/lib/13/03/app/navigation/app_router_delegate.dart b/lib/13/03/app/navigation/app_router_delegate.dart new file mode 100644 index 0000000..6600a0d --- /dev/null +++ b/lib/13/03/app/navigation/app_router_delegate.dart @@ -0,0 +1,114 @@ +import 'package:flutter/material.dart'; + +import '../../pages/color/color_page.dart'; +import '../../pages/empty/empty_page.dart'; +import '../../pages/settings/settings_page.dart'; +import '../../pages/counter/counter_page.dart'; +import '../../pages/user/user_page.dart'; +import '../../transition/fade_transition_page.dart'; +import '../../transition/no_transition_page.dart'; + +const List kDestinationsPaths = [ + '/color', + '/counter', + '/user', + '/settings', +]; + +AppRouterDelegate router = AppRouterDelegate(); + +class AppRouterDelegate extends RouterDelegate with ChangeNotifier { + String _path = '/color'; + + String get path => _path; + + set path(String value) { + if (_path == value) return; + _path = value; + notifyListeners(); + } + + @override + Widget build(BuildContext context) { + return Navigator( + onPopPage: _onPopPage, + pages: _buildPageByPath(path), + ); + } + + List _buildPageByPath(String path) { + Widget? child; + if (path == kDestinationsPaths[0]) { + child = const ColorPage(); + } + if (path == kDestinationsPaths[1]) { + child = const CounterPage(); + } + if (path == kDestinationsPaths[2]) { + child = const UserPage(); + } + if (path == kDestinationsPaths[3]) { + child = const SettingPage(); + } + return [ + FadeTransitionPage( + key: ValueKey(path), + child: child ?? const EmptyPage(), + ) + ]; + } + + @override + Future popRoute() async { + print('=======popRoute========='); + return true; + } + + bool _onPopPage(Route route, result) { + return route.didPop(result); + } + + @override + Future setNewRoutePath(configuration) async {} +} + +// class AppRouterDelegate extends RouterDelegate with ChangeNotifier, PopNavigatorRouterDelegateMixin { +// +// List _value = ['/']; +// +// +// List get value => _value; +// +// set value(List value){ +// _value = value; +// notifyListeners(); +// } +// +// @override +// Widget build(BuildContext context) { +// return Navigator( +// onPopPage: _onPopPage, +// pages: _value.map((e) => _pageMap[e]!).toList(), +// ); +// } +// +// final Map _pageMap = const { +// '/': MaterialPage(child: HomePage()), +// 'a': MaterialPage(child: PageA()), +// 'b': MaterialPage(child: PageB()), +// 'c': MaterialPage(child: PageC()), +// }; +// +// bool _onPopPage(Route route, result) { +// _value = List.of(_value)..removeLast(); +// notifyListeners(); +// return route.didPop(result); +// } +// +// @override +// GlobalKey? navigatorKey = GlobalKey(); +// +// @override +// Future setNewRoutePath(String configuration) async{ +// } +// } diff --git a/lib/13/03/app/navigation/views/app_navigation_rail.dart b/lib/13/03/app/navigation/views/app_navigation_rail.dart new file mode 100644 index 0000000..71e22b7 --- /dev/null +++ b/lib/13/03/app/navigation/views/app_navigation_rail.dart @@ -0,0 +1,53 @@ +import 'package:flutter/material.dart'; +import '../app_router_delegate.dart'; + +class AppNavigationRail extends StatefulWidget { + const AppNavigationRail({super.key}); + + @override + State createState() => _AppNavigationRailState(); +} + +class _AppNavigationRailState extends State { + final List destinations = const [ + NavigationRailDestination(icon: Icon(Icons.color_lens_outlined), label: Text("颜色板")), + NavigationRailDestination(icon: Icon(Icons.add_chart), label: Text("计数器")), + NavigationRailDestination(icon: Icon(Icons.person), label: Text("我的")), + NavigationRailDestination(icon: Icon(Icons.settings), label: Text("设置")), + ]; + + @override + void initState() { + super.initState(); + router.addListener(_onRouterChange); + } + + @override + void dispose() { + router.removeListener(_onRouterChange); + super.dispose(); + } + + int _index = 0 ; + + @override + Widget build(BuildContext context) { + return NavigationRail( + labelType: NavigationRailLabelType.all, + onDestinationSelected: _onDestinationSelected, + destinations: destinations, + selectedIndex: _index, + ); + } + + void _onDestinationSelected(int index) { + router.path = kDestinationsPaths[index]; + } + + void _onRouterChange() { + _index = kDestinationsPaths.indexOf(router.path); + setState(() { + + }); + } +} \ No newline at end of file diff --git a/lib/13/03/app/unit_app.dart b/lib/13/03/app/unit_app.dart new file mode 100644 index 0000000..5332b5d --- /dev/null +++ b/lib/13/03/app/unit_app.dart @@ -0,0 +1,38 @@ +import 'package:flutter/material.dart'; +import 'navigation/app_router_delegate.dart'; +import 'navigation/views/app_navigation_rail.dart'; + +class UnitApp extends StatelessWidget { + const UnitApp({super.key}); + + @override + Widget build(BuildContext context) { + + return MaterialApp( + theme: ThemeData( + appBarTheme: const AppBarTheme( + elevation: 0, + iconTheme: IconThemeData(color: Colors.black), + titleTextStyle: TextStyle( + color: Colors.black, + fontSize: 18, + fontWeight: FontWeight.bold, + ))), + debugShowCheckedModeBanner: false, + home: Scaffold( + body: Row( + children: [ + const AppNavigationRail(), + Expanded( + child: Router( + routerDelegate: router, + backButtonDispatcher: RootBackButtonDispatcher(), + ), + ), + ], + ), + )); + } +} + + diff --git a/lib/13/03/main.dart b/lib/13/03/main.dart index 881b6ec..38c9d78 100644 --- a/lib/13/03/main.dart +++ b/lib/13/03/main.dart @@ -1,11 +1,14 @@ import 'package:flutter/material.dart'; -import 'pages/app/app.dart'; +import 'app/unit_app.dart'; +import 'app/navigation/app_router_delegate.dart'; + + void main() { - runApp(const App()); + runApp(const UnitApp()); } diff --git a/lib/13/03/pages/color/color_page.dart b/lib/13/03/pages/color/color_page.dart new file mode 100644 index 0000000..6fd4e70 --- /dev/null +++ b/lib/13/03/pages/color/color_page.dart @@ -0,0 +1,52 @@ +import 'package:flutter/material.dart'; +import 'package:iroute/common/components/colors_panel.dart'; +import 'package:iroute/common/pages/stl_color_page.dart'; + +// class HomePage extends StatelessWidget { +// const HomePage({super.key}); +// +// @override +// Widget build(BuildContext context) { +// return Scaffold( +// body: const Center(child: Text('HomePage'))); +// } +// } + + +class ColorPage extends StatefulWidget { + const ColorPage({super.key}); + + @override + State createState() => _ColorPageState(); +} + +class _ColorPageState extends State { + final List _colors = [ + Colors.red, Colors.black, Colors.blue, Colors.green, Colors.orange, + Colors.pink, Colors.purple, Colors.indigo, Colors.amber, Colors.cyan, + Colors.redAccent, Colors.grey, Colors.blueAccent, Colors.greenAccent, Colors.orangeAccent, + Colors.pinkAccent, Colors.purpleAccent, Colors.indigoAccent, Colors.amberAccent, Colors.cyanAccent, + ]; + + @override + Widget build(BuildContext context) { + return Scaffold( + // appBar: AppBar(title:const Text('颜色主页')), + floatingActionButton: FloatingActionButton( + onPressed: _toAddPage, + child: const Icon(Icons.add), + ), + body: ColorsPanel( + colors: _colors, + onSelect: _selectColor, + ), + ); + } + + void _selectColor(Color color){ + // String value = color.value.toRadixString(16); + } + + void _toAddPage() async { + } +} \ No newline at end of file diff --git a/lib/13/03/pages/counter/counter_page.dart b/lib/13/03/pages/counter/counter_page.dart new file mode 100644 index 0000000..b5b2e17 --- /dev/null +++ b/lib/13/03/pages/counter/counter_page.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; + +class CounterPage extends StatefulWidget { + const CounterPage({super.key}); + + @override + State createState() => _CounterPageState(); +} + +class _CounterPageState extends State { + int _counter = 0; + + void _incrementCounter() { + setState(() { + _counter++; + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'You have pushed the button this many times:', + ), + Text( + '$_counter', + style: Theme.of(context).textTheme.headlineMedium, + ), + ], + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), + ); + } +} \ No newline at end of file diff --git a/lib/13/03/pages/empty/empty_page.dart b/lib/13/03/pages/empty/empty_page.dart new file mode 100644 index 0000000..e9064a8 --- /dev/null +++ b/lib/13/03/pages/empty/empty_page.dart @@ -0,0 +1,30 @@ +import 'package:flutter/material.dart'; + +class EmptyPage extends StatelessWidget { + const EmptyPage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('界面走丢了'), + ), + body: Scaffold( + body: Center( + child: Wrap( + spacing: 16, + crossAxisAlignment: WrapCrossAlignment.center, + direction: Axis.vertical, + children: [ + Icon(Icons.nearby_error,size: 64, color: Colors.grey), + Text( + '404 界面丢失', + style: TextStyle(fontSize: 24, color: Colors.grey), + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/13/03/pages/settings/settings_page.dart b/lib/13/03/pages/settings/settings_page.dart new file mode 100644 index 0000000..0b53503 --- /dev/null +++ b/lib/13/03/pages/settings/settings_page.dart @@ -0,0 +1,11 @@ +import 'package:flutter/material.dart'; + +class SettingPage extends StatelessWidget { + const SettingPage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + body:Center(child: Text('SettingPage'))); + } +} diff --git a/lib/13/03/pages/user/user_page.dart b/lib/13/03/pages/user/user_page.dart new file mode 100644 index 0000000..aba9710 --- /dev/null +++ b/lib/13/03/pages/user/user_page.dart @@ -0,0 +1,11 @@ +import 'package:flutter/material.dart'; + +class UserPage extends StatelessWidget { + const UserPage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + body:Center(child: Text('UserPage'))); + } +} diff --git a/lib/13/03/transition/fade_transition_page.dart b/lib/13/03/transition/fade_transition_page.dart new file mode 100644 index 0000000..552171b --- /dev/null +++ b/lib/13/03/transition/fade_transition_page.dart @@ -0,0 +1,53 @@ +// Copyright 2021, the Flutter project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:flutter/material.dart'; + +class FadeTransitionPage extends Page { + final Widget child; + final Duration duration; + + const FadeTransitionPage({ + super.key, + required this.child, + this.duration = const Duration(milliseconds: 300), + }); + + @override + Route createRoute(BuildContext context) => + PageBasedFadeTransitionRoute(this); +} + +class PageBasedFadeTransitionRoute extends PageRoute { + final FadeTransitionPage _page; + + PageBasedFadeTransitionRoute(this._page) : super(settings: _page); + + @override + Color? get barrierColor => null; + + @override + String? get barrierLabel => null; + + @override + Duration get transitionDuration => _page.duration; + + @override + bool get maintainState => true; + + @override + Widget buildPage(BuildContext context, Animation animation, + Animation secondaryAnimation) { + var curveTween = CurveTween(curve: Curves.easeIn); + return FadeTransition( + opacity: animation.drive(curveTween), + child: (settings as FadeTransitionPage).child, + ); + } + + @override + Widget buildTransitions(BuildContext context, Animation animation, + Animation secondaryAnimation, Widget child) => + child; +} diff --git a/lib/13/03/transition/no_transition_page.dart b/lib/13/03/transition/no_transition_page.dart new file mode 100644 index 0000000..291910b --- /dev/null +++ b/lib/13/03/transition/no_transition_page.dart @@ -0,0 +1,47 @@ +// Copyright 2021, the Flutter project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:flutter/material.dart'; + +class NoTransitionPage extends Page { + final Widget child; + + const NoTransitionPage({ + super.key, + required this.child, + }); + + @override + Route createRoute(BuildContext context) => NoTransitionRoute(this); +} + +class NoTransitionRoute extends PageRoute { + + final NoTransitionPage _page; + + NoTransitionRoute(this._page) : super(settings: _page); + + @override + Color? get barrierColor => null; + + @override + String? get barrierLabel => null; + + @override + Duration get transitionDuration => const Duration(milliseconds: 0); + + @override + bool get maintainState => true; + + @override + Widget buildPage(BuildContext context, Animation animation, + Animation secondaryAnimation) { + return (settings as NoTransitionPage).child; + } + + @override + Widget buildTransitions(BuildContext context, Animation animation, + Animation secondaryAnimation, Widget child) => + child; +} diff --git a/lib/13/03_/main.dart b/lib/13/03_/main.dart new file mode 100644 index 0000000..881b6ec --- /dev/null +++ b/lib/13/03_/main.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +import 'pages/app/app.dart'; + + + +void main() { + runApp(const App()); +} + + + + diff --git a/lib/13/03/menus.dart b/lib/13/03_/menus.dart similarity index 100% rename from lib/13/03/menus.dart rename to lib/13/03_/menus.dart diff --git a/lib/13/03/pages/app/app.dart b/lib/13/03_/pages/app/app.dart similarity index 100% rename from lib/13/03/pages/app/app.dart rename to lib/13/03_/pages/app/app.dart diff --git a/lib/13/03/pages/app/root_content.dart b/lib/13/03_/pages/app/root_content.dart similarity index 100% rename from lib/13/03/pages/app/root_content.dart rename to lib/13/03_/pages/app/root_content.dart diff --git a/lib/13/04/app/navigation/app_router_delegate.dart b/lib/13/04/app/navigation/app_router_delegate.dart new file mode 100644 index 0000000..57f8479 --- /dev/null +++ b/lib/13/04/app/navigation/app_router_delegate.dart @@ -0,0 +1,179 @@ +import 'dart:async'; +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:iroute/13/04/app/navigation/router/iroute.dart'; + +import '../../pages/color/color_page.dart'; +import '../../pages/empty/empty_page.dart'; +import '../../pages/settings/settings_page.dart'; +import '../../pages/counter/counter_page.dart'; +import '../../pages/user/user_page.dart'; +import '../../transition/fade_transition_page.dart'; +import '../../pages/color/color_add_page.dart'; + +const List kDestinationsPaths = [ + '/color', + '/counter', + '/user', + '/settings', +]; + +AppRouterDelegate router = AppRouterDelegate(); + +class AppRouterDelegate extends RouterDelegate with ChangeNotifier { + String _path = '/color'; + + String get path => _path; + + int? get activeIndex { + if(path.startsWith('/color')) return 0; + if(path.startsWith('/counter')) return 1; + if(path.startsWith('/user')) return 2; + if(path.startsWith('/settings')) return 3; + return null; + } + + late Completer completer; + Future changePathForResult(String value) async{ + completer = Completer(); + path = value; + return completer.future; + } + + set path(String value) { + if (_path == value) return; + _path = value; + notifyListeners(); + } + + // IRoute? parserPath(String path){ + // + // List parts = path.split('/'); + // String lever1 = '/${parts[1]}'; + // List iRoutes = kDestinationsIRoutes.where((e) => e.path == lever1).toList(); + // + // int counter = 2; + // + // IRoute? result; + // String check = lever1; + // for(int i = 0;i _buildPageByPath(String path) { + + + + Widget? child; + List result = []; + if(path.startsWith('/color')){ + result.add( FadeTransitionPage( + key: ValueKey('/color'), + child:const ColorPage(), + )); + + + if(path == '/color/add'){ + result.add( FadeTransitionPage( + key: ValueKey('/color/add'), + child:const ColorAddPage(), + )); + } + return result; + } + + if (path == kDestinationsPaths[0]) { + child = const ColorPage(); + } + if (path == kDestinationsPaths[1]) { + child = const CounterPage(); + } + if (path == kDestinationsPaths[2]) { + child = const UserPage(); + } + if (path == kDestinationsPaths[3]) { + child = const SettingPage(); + } + return [ + FadeTransitionPage( + // key: ValueKey(path), + child: child ?? const EmptyPage(), + ) + ]; + } + + @override + Future popRoute() async { + print('=======popRoute========='); + return true; + } + + bool _onPopPage(Route route, result) { + if(path == '/color/add'){ + completer.complete(result); + path = '/color'; + } + return route.didPop(result); + } + + @override + Future setNewRoutePath(configuration) async {} +} + +// class AppRouterDelegate extends RouterDelegate with ChangeNotifier, PopNavigatorRouterDelegateMixin { +// +// List _value = ['/']; +// +// +// List get value => _value; +// +// set value(List value){ +// _value = value; +// notifyListeners(); +// } +// +// @override +// Widget build(BuildContext context) { +// return Navigator( +// onPopPage: _onPopPage, +// pages: _value.map((e) => _pageMap[e]!).toList(), +// ); +// } +// +// final Map _pageMap = const { +// '/': MaterialPage(child: HomePage()), +// 'a': MaterialPage(child: PageA()), +// 'b': MaterialPage(child: PageB()), +// 'c': MaterialPage(child: PageC()), +// }; +// +// bool _onPopPage(Route route, result) { +// _value = List.of(_value)..removeLast(); +// notifyListeners(); +// return route.didPop(result); +// } +// +// @override +// GlobalKey? navigatorKey = GlobalKey(); +// +// @override +// Future setNewRoutePath(String configuration) async{ +// } +// } diff --git a/lib/13/04/app/navigation/router/iroute.dart b/lib/13/04/app/navigation/router/iroute.dart new file mode 100644 index 0000000..b703af9 --- /dev/null +++ b/lib/13/04/app/navigation/router/iroute.dart @@ -0,0 +1,37 @@ +class IRoute { + final String path; + final List children; + + const IRoute({required this.path, this.children = const []}); + + @override + String toString() { + return 'IRoute{path: $path, children: $children}'; + } + + List list(){ + + return []; + } + +} + + +const List kDestinationsIRoutes = [ + IRoute( + path: '/color', + children: [ + IRoute(path: '/color/add'), + IRoute(path: '/color/detail'), + ], + ), + IRoute( + path: '/counter', + ), + IRoute( + path: '/user', + ), + IRoute( + path: '/settings', + ), +]; diff --git a/lib/13/04/app/navigation/views/app_navigation_rail.dart b/lib/13/04/app/navigation/views/app_navigation_rail.dart new file mode 100644 index 0000000..2899ea2 --- /dev/null +++ b/lib/13/04/app/navigation/views/app_navigation_rail.dart @@ -0,0 +1,50 @@ +import 'package:flutter/material.dart'; +import '../app_router_delegate.dart'; + +class AppNavigationRail extends StatefulWidget { + const AppNavigationRail({super.key}); + + @override + State createState() => _AppNavigationRailState(); +} + +class _AppNavigationRailState extends State { + final List destinations = const [ + NavigationRailDestination(icon: Icon(Icons.color_lens_outlined), label: Text("颜色板")), + NavigationRailDestination(icon: Icon(Icons.add_chart), label: Text("计数器")), + NavigationRailDestination(icon: Icon(Icons.person), label: Text("我的")), + NavigationRailDestination(icon: Icon(Icons.settings), label: Text("设置")), + ]; + + @override + void initState() { + super.initState(); + router.addListener(_onRouterChange); + } + + @override + void dispose() { + router.removeListener(_onRouterChange); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return NavigationRail( + labelType: NavigationRailLabelType.all, + onDestinationSelected: _onDestinationSelected, + destinations: destinations, + selectedIndex: router.activeIndex, + ); + } + + void _onDestinationSelected(int index) { + router.path = kDestinationsPaths[index]; + } + + void _onRouterChange() { + setState(() { + + }); + } +} \ No newline at end of file diff --git a/lib/13/04/app/unit_app.dart b/lib/13/04/app/unit_app.dart new file mode 100644 index 0000000..5332b5d --- /dev/null +++ b/lib/13/04/app/unit_app.dart @@ -0,0 +1,38 @@ +import 'package:flutter/material.dart'; +import 'navigation/app_router_delegate.dart'; +import 'navigation/views/app_navigation_rail.dart'; + +class UnitApp extends StatelessWidget { + const UnitApp({super.key}); + + @override + Widget build(BuildContext context) { + + return MaterialApp( + theme: ThemeData( + appBarTheme: const AppBarTheme( + elevation: 0, + iconTheme: IconThemeData(color: Colors.black), + titleTextStyle: TextStyle( + color: Colors.black, + fontSize: 18, + fontWeight: FontWeight.bold, + ))), + debugShowCheckedModeBanner: false, + home: Scaffold( + body: Row( + children: [ + const AppNavigationRail(), + Expanded( + child: Router( + routerDelegate: router, + backButtonDispatcher: RootBackButtonDispatcher(), + ), + ), + ], + ), + )); + } +} + + diff --git a/lib/13/04/main.dart b/lib/13/04/main.dart new file mode 100644 index 0000000..38c9d78 --- /dev/null +++ b/lib/13/04/main.dart @@ -0,0 +1,16 @@ +import 'package:flutter/material.dart'; + +import 'app/unit_app.dart'; +import 'app/navigation/app_router_delegate.dart'; + + + + + +void main() { + runApp(const UnitApp()); +} + + + + diff --git a/lib/13/04/pages/color/color_add_page.dart b/lib/13/04/pages/color/color_add_page.dart new file mode 100644 index 0000000..bcc647b --- /dev/null +++ b/lib/13/04/pages/color/color_add_page.dart @@ -0,0 +1,67 @@ +import 'dart:math'; + +import 'package:flutter/material.dart'; + +class ColorAddPage extends StatefulWidget { + const ColorAddPage({super.key}); + + @override + State createState() => _ColorAddPageState(); +} + +class _ColorAddPageState extends State { + late Color _color; + + @override + void initState() { + super.initState(); + _color = randomColor; + } + + @override + Widget build(BuildContext context) { + String text = '# ${_color.value.toRadixString(16)}'; + return Scaffold( + // appBar: AppBar( + // title: Text('添加颜色'), + // actions: [IconButton(onPressed: _selectColor, icon: Icon(Icons.check ))], + // ), + body: Padding( + padding: const EdgeInsets.symmetric(horizontal: 16.0,vertical: 20), + child: Row( + children: [ + Expanded(child: Text(text,style: TextStyle(color: _color,fontSize: 24,letterSpacing: 4),)), + Container( + margin: EdgeInsets.only(left: 10), + width: 40, + height: 40, + child: Icon( + Icons.sell_outlined, + color: Colors.white, + ), + decoration: BoxDecoration( + color: _color, + borderRadius: BorderRadius.circular(8), + ), + ), + ], + ), + ), + ); + } + + Random _random = Random(); + + Color get randomColor { + return Color.fromARGB( + 255, + _random.nextInt(256), + _random.nextInt(256), + _random.nextInt(256), + ); + } + + void _selectColor() { + Navigator.of(context).pop(_color); + } +} diff --git a/lib/13/04/pages/color/color_page.dart b/lib/13/04/pages/color/color_page.dart new file mode 100644 index 0000000..7d41fad --- /dev/null +++ b/lib/13/04/pages/color/color_page.dart @@ -0,0 +1,59 @@ +import 'package:flutter/material.dart'; +import 'package:iroute/common/components/colors_panel.dart'; +import 'package:iroute/common/pages/stl_color_page.dart'; +import '../../app/navigation/app_router_delegate.dart'; + +// class HomePage extends StatelessWidget { +// const HomePage({super.key}); +// +// @override +// Widget build(BuildContext context) { +// return Scaffold( +// body: const Center(child: Text('HomePage'))); +// } +// } + + +class ColorPage extends StatefulWidget { + const ColorPage({super.key}); + + @override + State createState() => _ColorPageState(); +} + +class _ColorPageState extends State { + final List _colors = [ + Colors.red, Colors.black, Colors.blue, Colors.green, Colors.orange, + Colors.pink, Colors.purple, Colors.indigo, Colors.amber, Colors.cyan, + Colors.redAccent, Colors.grey, Colors.blueAccent, Colors.greenAccent, Colors.orangeAccent, + Colors.pinkAccent, Colors.purpleAccent, Colors.indigoAccent, Colors.amberAccent, Colors.cyanAccent, + ]; + + @override + Widget build(BuildContext context) { + return Scaffold( + // appBar: AppBar(title:const Text('颜色主页')), + floatingActionButton: FloatingActionButton( + onPressed: _toAddPage, + child: const Icon(Icons.add), + ), + body: ColorsPanel( + colors: _colors, + onSelect: _selectColor, + ), + ); + } + + void _selectColor(Color color){ + // String value = color.value.toRadixString(16); + } + + void _toAddPage() async { + dynamic color = await router.changePathForResult('/color/add'); + if (color != null) { + setState(() { + _colors.add(color); + }); + } + } +} \ No newline at end of file diff --git a/lib/13/04/pages/counter/counter_page.dart b/lib/13/04/pages/counter/counter_page.dart new file mode 100644 index 0000000..b5b2e17 --- /dev/null +++ b/lib/13/04/pages/counter/counter_page.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; + +class CounterPage extends StatefulWidget { + const CounterPage({super.key}); + + @override + State createState() => _CounterPageState(); +} + +class _CounterPageState extends State { + int _counter = 0; + + void _incrementCounter() { + setState(() { + _counter++; + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'You have pushed the button this many times:', + ), + Text( + '$_counter', + style: Theme.of(context).textTheme.headlineMedium, + ), + ], + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), + ); + } +} \ No newline at end of file diff --git a/lib/13/04/pages/empty/empty_page.dart b/lib/13/04/pages/empty/empty_page.dart new file mode 100644 index 0000000..e9064a8 --- /dev/null +++ b/lib/13/04/pages/empty/empty_page.dart @@ -0,0 +1,30 @@ +import 'package:flutter/material.dart'; + +class EmptyPage extends StatelessWidget { + const EmptyPage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('界面走丢了'), + ), + body: Scaffold( + body: Center( + child: Wrap( + spacing: 16, + crossAxisAlignment: WrapCrossAlignment.center, + direction: Axis.vertical, + children: [ + Icon(Icons.nearby_error,size: 64, color: Colors.grey), + Text( + '404 界面丢失', + style: TextStyle(fontSize: 24, color: Colors.grey), + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/13/04/pages/settings/settings_page.dart b/lib/13/04/pages/settings/settings_page.dart new file mode 100644 index 0000000..0b53503 --- /dev/null +++ b/lib/13/04/pages/settings/settings_page.dart @@ -0,0 +1,11 @@ +import 'package:flutter/material.dart'; + +class SettingPage extends StatelessWidget { + const SettingPage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + body:Center(child: Text('SettingPage'))); + } +} diff --git a/lib/13/04/pages/user/user_page.dart b/lib/13/04/pages/user/user_page.dart new file mode 100644 index 0000000..aba9710 --- /dev/null +++ b/lib/13/04/pages/user/user_page.dart @@ -0,0 +1,11 @@ +import 'package:flutter/material.dart'; + +class UserPage extends StatelessWidget { + const UserPage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + body:Center(child: Text('UserPage'))); + } +} diff --git a/lib/13/04/transition/fade_transition_page.dart b/lib/13/04/transition/fade_transition_page.dart new file mode 100644 index 0000000..552171b --- /dev/null +++ b/lib/13/04/transition/fade_transition_page.dart @@ -0,0 +1,53 @@ +// Copyright 2021, the Flutter project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:flutter/material.dart'; + +class FadeTransitionPage extends Page { + final Widget child; + final Duration duration; + + const FadeTransitionPage({ + super.key, + required this.child, + this.duration = const Duration(milliseconds: 300), + }); + + @override + Route createRoute(BuildContext context) => + PageBasedFadeTransitionRoute(this); +} + +class PageBasedFadeTransitionRoute extends PageRoute { + final FadeTransitionPage _page; + + PageBasedFadeTransitionRoute(this._page) : super(settings: _page); + + @override + Color? get barrierColor => null; + + @override + String? get barrierLabel => null; + + @override + Duration get transitionDuration => _page.duration; + + @override + bool get maintainState => true; + + @override + Widget buildPage(BuildContext context, Animation animation, + Animation secondaryAnimation) { + var curveTween = CurveTween(curve: Curves.easeIn); + return FadeTransition( + opacity: animation.drive(curveTween), + child: (settings as FadeTransitionPage).child, + ); + } + + @override + Widget buildTransitions(BuildContext context, Animation animation, + Animation secondaryAnimation, Widget child) => + child; +} diff --git a/lib/13/04/transition/no_transition_page.dart b/lib/13/04/transition/no_transition_page.dart new file mode 100644 index 0000000..291910b --- /dev/null +++ b/lib/13/04/transition/no_transition_page.dart @@ -0,0 +1,47 @@ +// Copyright 2021, the Flutter project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:flutter/material.dart'; + +class NoTransitionPage extends Page { + final Widget child; + + const NoTransitionPage({ + super.key, + required this.child, + }); + + @override + Route createRoute(BuildContext context) => NoTransitionRoute(this); +} + +class NoTransitionRoute extends PageRoute { + + final NoTransitionPage _page; + + NoTransitionRoute(this._page) : super(settings: _page); + + @override + Color? get barrierColor => null; + + @override + String? get barrierLabel => null; + + @override + Duration get transitionDuration => const Duration(milliseconds: 0); + + @override + bool get maintainState => true; + + @override + Widget buildPage(BuildContext context, Animation animation, + Animation secondaryAnimation) { + return (settings as NoTransitionPage).child; + } + + @override + Widget buildTransitions(BuildContext context, Animation animation, + Animation secondaryAnimation, Widget child) => + child; +} diff --git a/lib/13/节点介绍.txt b/lib/13/节点介绍.txt new file mode 100644 index 0000000..7897938 --- /dev/null +++ b/lib/13/节点介绍.txt @@ -0,0 +1,6 @@ +01: Router#RouterDelegate 基础使用 + 改造基于数据控制 A、B、C 三个界面跳转。 + +02: 导航 2.0 中返回操作介绍 + +03: 侧栏菜单导航 V1 \ No newline at end of file diff --git a/test/parser/main.dart b/test/parser/main.dart new file mode 100644 index 0000000..403d9a6 --- /dev/null +++ b/test/parser/main.dart @@ -0,0 +1,46 @@ +import 'package:iroute/13/04/app/navigation/router/iroute.dart'; + +void main() { + String path = '/color/detail/a'; + // List parts = path.split('/'); + // print(parts); + // print(parserPath(path)); + + Uri uri = Uri.parse(path); + print(uri.fragment); + print(uri.pathSegments); + + List parts = uri.pathSegments; + + parts = List.of(parts)..removeLast(); + String result = parts.join('/'); + print(result); +} + + +IRoute? parserPath(String path){ + + List parts = path.split('/'); + String lever1 = '/${parts[1]}'; + List iRoutes = kDestinationsIRoutes.where((e) => e.path == lever1).toList(); + + int counter = 2; + + IRoute? result; + String check = lever1; + List children = iRoutes.first.children; + + check = check +"/" + parts[counter]; + + for(int i = 0;i