From d63f82a75fb93325ffdbd889a8f24c8a5226a5e1 Mon Sep 17 00:00:00 2001 From: Chen Peng Date: Mon, 6 May 2024 17:02:52 +0800 Subject: [PATCH] clean --- .../flutter_web/lib/routes/notes/layout.dart | 6 ++-- packages/you_flutter/lib/note.dart | 2 +- packages/you_flutter/lib/src/note/note.dart | 30 +++++-------------- .../you_flutter/lib/src/note/note_layout.dart | 2 -- packages/you_flutter/lib/src/router.dart | 24 +++++++-------- 5 files changed, 23 insertions(+), 41 deletions(-) diff --git a/notes/flutter_web/lib/routes/notes/layout.dart b/notes/flutter_web/lib/routes/notes/layout.dart index ffbb8d22..0efa169f 100644 --- a/notes/flutter_web/lib/routes/notes/layout.dart +++ b/notes/flutter_web/lib/routes/notes/layout.dart @@ -5,7 +5,7 @@ import 'package:you_flutter/state.dart'; /// [NoteLayoutBuilder] @ToType(type: ToNote) -NoteResult layout(BuildContext context, NoteResult child) { +NoteMixin layout(BuildContext context, NoteMixin child) { // ignore: unnecessary_type_check assert(layout is NoteLayoutBuilder); return NoteLayout(child: child); @@ -13,8 +13,8 @@ NoteResult layout(BuildContext context, NoteResult child) { /// 一个极简的笔记布局范例 /// 左边routes树,右边页面内容 -final class NoteLayout extends StatelessWidget with NoteResult { - final NoteResult child; +final class NoteLayout extends StatelessWidget with NoteMixin { + final NoteMixin child; const NoteLayout({super.key, required this.child}); diff --git a/packages/you_flutter/lib/note.dart b/packages/you_flutter/lib/note.dart index 6940816a..42209885 100644 --- a/packages/you_flutter/lib/note.dart +++ b/packages/you_flutter/lib/note.dart @@ -1,6 +1,6 @@ library note; -export 'src/note/note.dart' show ToNote, Cell, NoteBuilder,NoteResult, NoteLayoutBuilder, NoteSystem; +export 'src/note/note.dart' show ToNote, Cell, NoteBuilder,NoteMixin, NoteLayoutBuilder; export 'src/note/contents/contents.dart' show contents, Contents; export 'src/note/contents/mockup.dart' show MockupWindow; diff --git a/packages/you_flutter/lib/src/note/note.dart b/packages/you_flutter/lib/src/note/note.dart index 791f3ebb..71f14d35 100644 --- a/packages/you_flutter/lib/src/note/note.dart +++ b/packages/you_flutter/lib/src/note/note.dart @@ -13,9 +13,9 @@ import 'package:you_flutter/src/note/conventions.dart'; import 'package:http/http.dart' as http; typedef NoteBuilder = void Function(BuildContext context, Cell print); -typedef NoteLayoutBuilder = NoteResult Function(BuildContext context, NoteResult child); +typedef NoteLayoutBuilder = NoteMixin Function(BuildContext context, NoteMixin child); -mixin NoteResult on StatelessWidget { +mixin NoteMixin on StatelessWidget { Cell get cell; } @@ -29,23 +29,23 @@ base class ToNote extends To { }) : super( page: page == null ? null : (context) => _build(context, page), notFound: notFound == null ? null : (context) => _build(context, notFound), - layout: layout == null ? null : (context, child) => layout(context, child as NoteResult), + layout: layout == null ? null : (context, child) => layout(context, child as NoteMixin), ); - static NoteResult _build(BuildContext context, NoteBuilder page) { + static NoteMixin _build(BuildContext context, NoteBuilder page) { Cell cell = Cell.empty(); page.call(context, cell); - return _DefaultNotePage(cell: cell); + return _DefaultNote(cell: cell); } } /// 一个极简的笔记布局范例 /// 左边routes树,右边页面内容 -final class _DefaultNotePage extends StatelessWidget with NoteResult { +final class _DefaultNote extends StatelessWidget with NoteMixin { @override final Cell cell; - const _DefaultNotePage({required this.cell}); + const _DefaultNote({required this.cell}); @override Widget build(BuildContext context) { @@ -191,22 +191,6 @@ class NoteRoute { String get confAssetPath => conventions.noteConfAssetPath(path); } -class NoteSystem { - final To root; - - NoteSystem({ - required this.root, - }); - - static Future load({ - required To root, - }) async { - return NoteSystem( - root: root, - ); - } -} - base class Cell { Cell( Function(Cell print) callback, { diff --git a/packages/you_flutter/lib/src/note/note_layout.dart b/packages/you_flutter/lib/src/note/note_layout.dart index a3025209..6d6533dd 100644 --- a/packages/you_flutter/lib/src/note/note_layout.dart +++ b/packages/you_flutter/lib/src/note/note_layout.dart @@ -12,14 +12,12 @@ const Widget _cellSplitBlock = SizedBox(height: 18); @Deprecated("已被新router替代暂时保留,代码还没移植完") class LayoutScreen extends StatefulWidget with Screen { - final NoteSystem noteSystem; final NoteRoute note = NoteRoute.root(); final Cell rootCell; final NoteRoute rootNote = NoteRoute.root(); LayoutScreen({ super.key, - required this.noteSystem, required this.rootCell, }); diff --git a/packages/you_flutter/lib/src/router.dart b/packages/you_flutter/lib/src/router.dart index b589ec77..36391a15 100644 --- a/packages/you_flutter/lib/src/router.dart +++ b/packages/you_flutter/lib/src/router.dart @@ -127,7 +127,7 @@ final class YouRouter with RouterMixin { YouRouter get router => this; } -enum RouteNodeType { +enum ToPartType { /// static path : /settings static, @@ -140,7 +140,7 @@ enum RouteNodeType { /// /file/a/b/c.txt -> path==a/b/c.txt dynamicRest; - static RouteNodeType? parse(String name) { + static ToPartType? parse(String name) { for (var i in values) { if (i.name == name) { return i; @@ -161,7 +161,7 @@ base class To { final String part; late final String _name; - late final RouteNodeType _type; + late final ToPartType _type; late To _parent = this; @@ -286,14 +286,14 @@ base class To { // 忽略后缀'/' // next=="" 代表最后以 '/' 结尾,当前 segments==[""] - if (_type == RouteNodeType.static && next == "") { + if (_type == ToPartType.static && next == "") { return RouteUri._(uri: uri, to: this, routeParameters: params); } To? matchChild({required String segment}) { - To? matched = children.where((e) => e._type == RouteNodeType.static).where((e) => segment == e._name).firstOrNull; + To? matched = children.where((e) => e._type == ToPartType.static).where((e) => segment == e._name).firstOrNull; if (matched != null) return matched; - matched = children.where((e) => e._type == RouteNodeType.dynamic || e._type == RouteNodeType.dynamicRest).firstOrNull; + matched = children.where((e) => e._type == ToPartType.dynamic || e._type == ToPartType.dynamicRest).firstOrNull; if (matched != null) return matched; return null; } @@ -304,7 +304,7 @@ base class To { throw NotFoundError(invalidValue: uri); } - if (matchedNext._type == RouteNodeType.dynamicRest) { + if (matchedNext._type == ToPartType.dynamicRest) { // /tree/[...file] // /tree/x/y --> {"file":"x/y"} // /tree/x/y/ --> {"file":"x/y/"} @@ -315,7 +315,7 @@ base class To { if (next == "") { return RouteUri._(uri: uri, to: this, routeParameters: params); } - if (matchedNext._type == RouteNodeType.dynamic) { + if (matchedNext._type == ToPartType.dynamic) { params[matchedNext._name] = next; } } @@ -358,11 +358,11 @@ base class To { /// parse("user") --> (name:"user",type:ToNodeType.normal) /// parse("[id]") --> (name:"id", type:ToNodeType.dynamic) /// parse("[...path]") --> (name:"path",type:ToNodeType.dynamicAll) - static (String, RouteNodeType) _parse(String pattern) { + static (String, ToPartType) _parse(String pattern) { assert(pattern.isNotEmpty); if (pattern[0] != "[" || pattern[pattern.length - 1] != "]") { - return (pattern, RouteNodeType.static); + return (pattern, ToPartType.static); } assert(pattern != "[]"); @@ -373,9 +373,9 @@ base class To { final removeBrackets = pattern.substring(1, pattern.length - 1); if (removeBrackets.startsWith("...")) { - return (removeBrackets.substring(3), RouteNodeType.dynamicRest); + return (removeBrackets.substring(3), ToPartType.dynamicRest); } else { - return (removeBrackets, RouteNodeType.dynamic); + return (removeBrackets, ToPartType.dynamic); } }