Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

148 page anno config #149

Merged
merged 12 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bake
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ flutter_web.clean() { _run flutter_web flutter clean;
rm -rf build; }
flutter_web.upgrade() { _run flutter_web flutter pub upgrade ; }
flutter_web.gen() { #_run root dart run packages/you_cli/bin/cli.dart gen all --dir notes/flutter_web/;
_run root dart run packages/you_cli/bin/cli.dart gen routes.g.dart --dir notes/flutter_web/ # --async
_run root dart run packages/you_cli/bin/cli.dart gen routes --dir notes/flutter_web/ # --async
}
flutter_web.dev() { flutter_web.dev_html ; }
flutter_web.build() { flutter_web.build_html ;}
Expand Down
13 changes: 9 additions & 4 deletions notes/flutter_web/lib/routes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:you_flutter/router.dart';
import 'package:flutter_web/routes/page.dart';
import 'package:flutter_web/routes/layout.dart';
import 'package:flutter_web/routes/layout.dart' as _routes_layout;
import 'package:you_flutter/note.dart';
import 'package:flutter_web/routes/notes/page.dart' as _notes_page;
import 'package:flutter_web/routes/notes/layout.dart' as _notes_layout;
Expand Down Expand Up @@ -54,8 +54,8 @@ import 'package:flutter_web/routes/notes/Improve_app/RepaintBoundary/page.dart'
import 'package:flutter_web/routes/notes/Improve_app/event&listener&lifeycle/page.dart' as _event_listener_lifeycle_page;

mixin RoutesMixin {
final To root = To('routes', page: build, layout: layout, children: [
ToNote('notes', page: _notes_page.build, layout: _notes_layout.layout, children: [
final To root = To('routes', page: build, layout: _routes_layout.build, children: [
ToNote('notes', page: _notes_page.build, pageAnno: _Pages.notes, layout: _notes_layout.build, children: [
ToNote('research', children: [
ToNote('bash_note'),
ToNote('parameterized', page: _parameterized_page.build),
Expand Down Expand Up @@ -115,7 +115,7 @@ mixin RoutesMixin {
]),
ToNote('widgets', children: [
ToNote('specific_widgets', children: [
ToNote('button', page: _button_page.build),
ToNote('button', page: _button_page.build, pageAnno: _Pages.notes_widgets_specific_widgets_button),
]),
ToNote('container_widgets', children: [
ToNote('drawer'),
Expand Down Expand Up @@ -184,3 +184,8 @@ mixin RoutesMixin {
}

class Routes with RoutesMixin {}

class _Pages {
static const notes = PageAnnotation(label: "笔记", toType: ToNote);
static const notes_widgets_specific_widgets_button = PageAnnotation(label: "按钮", publish: true);
}
31 changes: 18 additions & 13 deletions notes/flutter_web/lib/routes/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'package:you_flutter/router.dart';
import 'package:you_flutter/state.dart';

/// [LayoutBuilder]
Widget layout(BuildContext context, Widget child) {
Widget build(BuildContext context, Widget child) {
// ignore: unnecessary_type_check
assert(layout is PageLayoutBuilder);
assert(build is PageLayoutBuilder);
return RootLayout(child: child);
}

Expand Down Expand Up @@ -91,14 +91,15 @@ class _NoteTree extends StatelessWidget {
Widget build(BuildContext context) {
final route = context.route$;
final colors = Theme.of(context).colorScheme;
final notes = routes.routes_notes
.toList(
includeThis: false,
)
.where((e) => e.isPage || e.isNonLeaf);
routes.routes_notes.expandTree(true, level: 1);
routes.routes_root.expandTree(true, level: 2);
return Watch((context) {
var noteList = notes.where((e) => e.isRoot ? true : e.parent.expand).toList();
final notes = routes.routes_notes
.toList(
includeThis: false,
where: (e) => e.parent.expand && (includeDraft.value || e.containsPublishNode),
)
.toList();

return Column(
children: [
Container(
Expand All @@ -110,7 +111,7 @@ class _NoteTree extends StatelessWidget {
]),
),
ListView(
children: noteList.map((e) => _noteItem(e, route, includeDraft.value)).toList(),
children: notes.map((e) => _noteItem(e, route, includeDraft.value)).toList(),
).expanded$(),
],
).constrainedBox$(
Expand All @@ -137,9 +138,13 @@ class _NoteTree extends StatelessWidget {

String title = "$iconExtend ${node.part}";
title = title.padLeft((node.level * 2) + title.length);
String publishLabel = "";
if (node.isLeafPage) {
publishLabel = node.isPublish ? "(已发布)" : "(草稿)";
}
return Align(
alignment: Alignment.centerLeft,
child: TextButton(onPressed: click, child: Text(title)),
child: TextButton(onPressed: click, child: Text('$title$publishLabel')),
);
}
}
Expand All @@ -157,9 +162,9 @@ extension _NoteTreeNode on To {
}

/// 展开层级数
void expandTree(bool value, {int level = 0}) {
if (level <= 0) return;
void expandTree(bool value, {int level = 1}) {
expand = value;
if (level <= 1) return;
for (var e in children) {
e.expandTree(value, level: level - 1);
}
Expand Down
23 changes: 6 additions & 17 deletions notes/flutter_web/lib/routes/notes/layout.dart
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
import 'package:flutter/material.dart';
import 'package:you_flutter/router.dart';
import 'package:you_flutter/note.dart';
import 'package:you_flutter/state.dart';

/// [NoteLayoutBuilder]
@ToType(type: ToNote)
NoteMixin layout(BuildContext context, NoteMixin child) {
NoteMixin build(BuildContext context, NoteMixin child) {
// ignore: unnecessary_type_check
assert(layout is NoteLayoutBuilder);
return NoteLayout(child: child);
assert(build is NoteLayoutBuilder);
return NoteRootLayout(child: child);
}

/// 一个极简的笔记布局范例
/// 左边routes树,右边页面内容
final class NoteLayout extends StatelessWidget with NoteMixin {
final class NoteRootLayout extends StatelessWidget with NoteMixin {
final NoteMixin child;

const NoteLayout({super.key, required this.child});
const NoteRootLayout({super.key, required this.child});

@override
Cell get cell => child.cell;

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: SelectionArea(
child: Watch((context) {
return SingleChildScrollView(child: child);
}),
),
),
);
return SingleChildScrollView(child: child);
}
}

Expand Down
3 changes: 2 additions & 1 deletion notes/flutter_web/lib/routes/notes/page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:flutter/widgets.dart';
import 'package:you_flutter/note.dart';
import 'package:you_flutter/router.dart';

/// [PageBuilder]
@PageAnnotation(label: "笔记", toType: ToNote)
void build(BuildContext context, Cell print) {
print(const MD(r'''
# home
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:flutter/material.dart';
import 'package:you_flutter/note.dart';
import 'package:you_flutter/router.dart';

@PageAnnotation(label: "按钮", publish: true)
void build(BuildContext context, Cell print) {
print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(const MD(r'''
# overview

Expand All @@ -16,7 +18,7 @@ the Material Design overview types and how they should be used in designs.
以下几种主要Button都继承自[ButtonStyleButton]
'''));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(Wrap(
children: [
ElevatedButton(onPressed: () {}, child: const Text("ElevatedButton")),
Expand All @@ -27,14 +29,14 @@ the Material Design overview types and how they should be used in designs.
],
));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(const MD(r'''
### IconButton

图标按钮。
'''));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(Row(
children: [
IconButton(onPressed: () {}, tooltip: "IconButton", icon: const Icon(Icons.wifi)),
Expand All @@ -43,14 +45,14 @@ the Material Design overview types and how they should be used in designs.
],
));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(const MD(r'''
### FloatingActionButton

浮动按钮,常见于[Scaffold]右下角的浮动按钮。
'''));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
int id = 0;

print(Row(
Expand Down Expand Up @@ -83,7 +85,7 @@ the Material Design overview types and how they should be used in designs.
],
));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(const MD(r'''
### 几个特殊的系统Button

Expand All @@ -96,7 +98,7 @@ the Material Design overview types and how they should be used in designs.
- [EndDrawerButton] A Material Design drawer icon overview
'''));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(const Row(
children: [
BackButton(),
Expand All @@ -106,7 +108,7 @@ the Material Design overview types and how they should be used in designs.
],
));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(const MD(r'''

### ToggleButtons
Expand All @@ -116,7 +118,7 @@ the Material Design overview types and how they should be used in designs.
> **📣提示**:此组件实现于Material 2,类似于Material 3的[SegmentedButton]。可用[SegmentedButton]替换之。
'''));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(Row(
children: [
ToggleButtons(
Expand All @@ -131,7 +133,7 @@ the Material Design overview types and how they should be used in designs.
],
));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(const MD(r'''
### SegmentedButton

Expand All @@ -142,7 +144,7 @@ the Material Design overview types and how they should be used in designs.
<https://m3.material.io/components/segmented-buttons>
'''));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(Row(
children: [
SegmentedButton<String>(
Expand All @@ -159,7 +161,7 @@ the Material Design overview types and how they should be used in designs.
],
));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(const MD(r'''
## 相关组件

Expand All @@ -175,7 +177,7 @@ GestureDetector(
```
'''));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(const MD(r'''
### Ink*组件

Expand All @@ -191,7 +193,7 @@ InkWell/InkResponse = GestureDetector + Material风格的动态效果 。
您在下面三种不同的文本上点点看区别:
'''));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(Column(
children: [
const Text("1.普通Text"),
Expand All @@ -206,14 +208,14 @@ InkWell/InkResponse = GestureDetector + Material风格的动态效果 。
],
));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(const MD(r'''
### ButtonBar

按钮的布局容器,可以按内容的实际宽度在行或列之间调整,您把下面范例中父容器Container.width调小些看看:
'''));

print.addCell(title:const Text("--------new cell------"));
print.addCell(title: const Text("--------new cell------"));
print(Container(
width: 600,
color: Colors.lime.shade50,
Expand Down
2 changes: 1 addition & 1 deletion notes/flutter_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:
code_builder: ^4.4.0
file: ^7.0.0
shared_preferences: ^2.2.2
meta: ^1.11.0
meta: ^1.12.0
stack_trace: ^1.11.1
source_map_stack_trace: ^2.1.1
http: ^1.2.1
Expand Down
2 changes: 2 additions & 0 deletions notes/learn_dart/test/@syntax/part/part1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
part of 'part_main.dart';
// import 'dart:math';//compile error:The part-of directive must be the only directive in a part.
8 changes: 8 additions & 0 deletions notes/learn_dart/test/@syntax/part/part_main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// 定义库
library;

// 导入可能需要的其他库或包
import 'dart:math';

// 这里可以放置一些公有接口或者类的声明
part "part1.dart";
32 changes: 32 additions & 0 deletions notes/learn_dart/test/dart_lang!sdk!pkg!analyzer/ast_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ignore_for_file: unnecessary_type_check

import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:test/test.dart';
import 'package:path/path.dart' as path;

void main() {
test('analyzer', () async {
String f = "test/dart_lang!sdk!pkg!analyzer/element_test.dart";
f = path.absolute(f);
var session = AnalysisContextCollection(
includedPaths: [f],
resourceProvider: PhysicalResourceProvider(),
).contexts[0].currentSession;
var result =await session.getResolvedUnit(f) as ResolvedUnitResult;
var findAnnotations=forAst<Annotation>(result.unit).toList();
print(findAnnotations.map((e)=>"${e.runtimeType} $e \n").join("\n"));
});
}

Iterable<FIND> forAst<FIND>(AstNode node)sync* {
// print("ast ${node.runtimeType}: $FIND");

if(node is FIND) yield node as FIND;
for (var i in node.childEntities) {
if (i is! AstNode) continue;
yield* forAst(i);
}
}
Loading
Loading