From 72c3cc607dc247e1218f027e5ee4ecd60363655a Mon Sep 17 00:00:00 2001 From: toly <1981462002@qq.com> Date: Wed, 27 Dec 2023 01:06:25 +0800 Subject: [PATCH] done --- lib/15/03/app/unit_app.dart | 1 + .../app/navigation/app_router_delegate.dart | 207 ------------------ lib/15/04/app/navigation/router/iroute.dart | 37 ---- .../navigation/views/app_navigation_rail.dart | 50 ----- lib/15/04/app/unit_app.dart | 38 ---- lib/15/04/main.dart | 16 -- lib/15/04/pages/color/color_add_page.dart | 102 --------- lib/15/04/pages/color/color_page.dart | 48 ---- lib/15/04/pages/counter/counter_page.dart | 43 ---- lib/15/04/pages/empty/empty_page.dart | 30 --- lib/15/04/pages/settings/settings_page.dart | 11 - lib/15/04/pages/user/user_page.dart | 11 - .../04/transition/fade_transition_page.dart | 53 ----- lib/15/04/transition/no_transition_page.dart | 47 ---- lib/16/01/app/unit_app.dart | 1 + lib/16/节点介绍.txt | 1 + 16 files changed, 3 insertions(+), 693 deletions(-) delete mode 100644 lib/15/04/app/navigation/app_router_delegate.dart delete mode 100644 lib/15/04/app/navigation/router/iroute.dart delete mode 100644 lib/15/04/app/navigation/views/app_navigation_rail.dart delete mode 100644 lib/15/04/app/unit_app.dart delete mode 100644 lib/15/04/main.dart delete mode 100644 lib/15/04/pages/color/color_add_page.dart delete mode 100644 lib/15/04/pages/color/color_page.dart delete mode 100644 lib/15/04/pages/counter/counter_page.dart delete mode 100644 lib/15/04/pages/empty/empty_page.dart delete mode 100644 lib/15/04/pages/settings/settings_page.dart delete mode 100644 lib/15/04/pages/user/user_page.dart delete mode 100644 lib/15/04/transition/fade_transition_page.dart delete mode 100644 lib/15/04/transition/no_transition_page.dart create mode 100644 lib/16/节点介绍.txt diff --git a/lib/15/03/app/unit_app.dart b/lib/15/03/app/unit_app.dart index 5332b5d..6558c74 100644 --- a/lib/15/03/app/unit_app.dart +++ b/lib/15/03/app/unit_app.dart @@ -10,6 +10,7 @@ class UnitApp extends StatelessWidget { return MaterialApp( theme: ThemeData( + useMaterial3: false, appBarTheme: const AppBarTheme( elevation: 0, iconTheme: IconThemeData(color: Colors.black), diff --git a/lib/15/04/app/navigation/app_router_delegate.dart b/lib/15/04/app/navigation/app_router_delegate.dart deleted file mode 100644 index 7f9d92f..0000000 --- a/lib/15/04/app/navigation/app_router_delegate.dart +++ /dev/null @@ -1,207 +0,0 @@ -import 'dart:async'; -import 'dart:io'; - -import 'package:flutter/material.dart'; -import 'package:iroute/common/pages/stl_color_page.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; - } - - final Map> _completerMap = {}; - - Completer? completer; - - Future changePathForResult(String value) async{ - Completer completer = Completer(); - _completerMap[value] = 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) { - if(path.startsWith('/color')){ - return buildColorPages(path); - } - - Widget? child; - 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(), - ) - ]; - } - - List buildColorPages(String path){ - List result = []; - Uri uri = Uri.parse(path); - for (String segment in uri.pathSegments) { - if(segment == 'color'){ - result.add( const FadeTransitionPage( - key: ValueKey('/color'), - child:ColorPage(), - )); - } - if(segment =='detail'){ - final Map queryParams = uri.queryParameters; - String? selectedColor = queryParams['color']; - if (selectedColor != null) { - Color color = Color(int.parse(selectedColor, radix: 16)); - result.add( FadeTransitionPage( - key: const ValueKey('/color/detail'), - child:StlColorPage(color: color), - )); - } - } - if(segment == 'add'){ - result.add( const FadeTransitionPage( - key: ValueKey('/color/add'), - child:ColorAddPage(), - )); - } - - } - return result; - } - - @override - Future popRoute() async { - print('=======popRoute========='); - return true; - } - - bool _onPopPage(Route route, result) { - if(_completerMap.containsKey(path)){ - _completerMap[path]?.complete(result); - _completerMap.remove(path); - } - - path = backPath(path); - return route.didPop(result); - } - - String backPath(String path){ - Uri uri = Uri.parse(path); - if(uri.pathSegments.length==1) return path; - List parts = List.of(uri.pathSegments)..removeLast(); - return '/${parts.join('/')}'; - } - - @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/15/04/app/navigation/router/iroute.dart b/lib/15/04/app/navigation/router/iroute.dart deleted file mode 100644 index b703af9..0000000 --- a/lib/15/04/app/navigation/router/iroute.dart +++ /dev/null @@ -1,37 +0,0 @@ -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/15/04/app/navigation/views/app_navigation_rail.dart b/lib/15/04/app/navigation/views/app_navigation_rail.dart deleted file mode 100644 index 2899ea2..0000000 --- a/lib/15/04/app/navigation/views/app_navigation_rail.dart +++ /dev/null @@ -1,50 +0,0 @@ -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/15/04/app/unit_app.dart b/lib/15/04/app/unit_app.dart deleted file mode 100644 index 5332b5d..0000000 --- a/lib/15/04/app/unit_app.dart +++ /dev/null @@ -1,38 +0,0 @@ -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/15/04/main.dart b/lib/15/04/main.dart deleted file mode 100644 index 38c9d78..0000000 --- a/lib/15/04/main.dart +++ /dev/null @@ -1,16 +0,0 @@ -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/15/04/pages/color/color_add_page.dart b/lib/15/04/pages/color/color_add_page.dart deleted file mode 100644 index b3cf660..0000000 --- a/lib/15/04/pages/color/color_add_page.dart +++ /dev/null @@ -1,102 +0,0 @@ -import 'dart:math'; - -import 'package:flutter/material.dart'; -import 'package:flutter_colorpicker/flutter_colorpicker.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( - bottomNavigationBar: Container( - margin: EdgeInsets.only(right:20,bottom: 20), - // color: Colors.redAccent, - child: Row( - textDirection:TextDirection.rtl, - children: [ - ElevatedButton(onPressed: (){ - Navigator.of(context).pop(_color); - - }, child: Text('添加')), - SizedBox(width: 12,), - OutlinedButton(onPressed: (){ - Navigator.of(context).pop(); - }, child: Text('取消')), - ], - ), - ), - body: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 16.0), - 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), - ), - ), - ], - ), - ), - ColorPicker( - colorPickerWidth:200, - // enableAlpha: false, - displayThumbColor:true, - pickerColor: _color, - paletteType: PaletteType.hueWheel, - onColorChanged: changeColor, - - ), - ], - ), - ); - } - - 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); - } - - void changeColor(Color value) { - _color = value; - setState(() { - - }); - } -} diff --git a/lib/15/04/pages/color/color_page.dart b/lib/15/04/pages/color/color_page.dart deleted file mode 100644 index 9c8ca6d..0000000 --- a/lib/15/04/pages/color/color_page.dart +++ /dev/null @@ -1,48 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:iroute/common/components/colors_panel.dart'; -import '../../app/navigation/app_router_delegate.dart'; - -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); - router.path = '/color/detail?color=$value'; - } - - void _toAddPage() async { - Color? color = await router.changePathForResult('/color/add'); - if (color != null) { - setState(() { - _colors.add(color); - }); - } - } -} \ No newline at end of file diff --git a/lib/15/04/pages/counter/counter_page.dart b/lib/15/04/pages/counter/counter_page.dart deleted file mode 100644 index b5b2e17..0000000 --- a/lib/15/04/pages/counter/counter_page.dart +++ /dev/null @@ -1,43 +0,0 @@ -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/15/04/pages/empty/empty_page.dart b/lib/15/04/pages/empty/empty_page.dart deleted file mode 100644 index e9064a8..0000000 --- a/lib/15/04/pages/empty/empty_page.dart +++ /dev/null @@ -1,30 +0,0 @@ -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/15/04/pages/settings/settings_page.dart b/lib/15/04/pages/settings/settings_page.dart deleted file mode 100644 index 0b53503..0000000 --- a/lib/15/04/pages/settings/settings_page.dart +++ /dev/null @@ -1,11 +0,0 @@ -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/15/04/pages/user/user_page.dart b/lib/15/04/pages/user/user_page.dart deleted file mode 100644 index aba9710..0000000 --- a/lib/15/04/pages/user/user_page.dart +++ /dev/null @@ -1,11 +0,0 @@ -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/15/04/transition/fade_transition_page.dart b/lib/15/04/transition/fade_transition_page.dart deleted file mode 100644 index 552171b..0000000 --- a/lib/15/04/transition/fade_transition_page.dart +++ /dev/null @@ -1,53 +0,0 @@ -// 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/15/04/transition/no_transition_page.dart b/lib/15/04/transition/no_transition_page.dart deleted file mode 100644 index 291910b..0000000 --- a/lib/15/04/transition/no_transition_page.dart +++ /dev/null @@ -1,47 +0,0 @@ -// 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/16/01/app/unit_app.dart b/lib/16/01/app/unit_app.dart index 5332b5d..de7e342 100644 --- a/lib/16/01/app/unit_app.dart +++ b/lib/16/01/app/unit_app.dart @@ -10,6 +10,7 @@ class UnitApp extends StatelessWidget { return MaterialApp( theme: ThemeData( + useMaterial3: false, appBarTheme: const AppBarTheme( elevation: 0, iconTheme: IconThemeData(color: Colors.black), diff --git a/lib/16/节点介绍.txt b/lib/16/节点介绍.txt new file mode 100644 index 0000000..dc8c3e1 --- /dev/null +++ b/lib/16/节点介绍.txt @@ -0,0 +1 @@ +01: 颜色添加页和详情页跳转 \ No newline at end of file