Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed Apr 26, 2024
1 parent 373834b commit 68064f9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 14 deletions.
2 changes: 1 addition & 1 deletion notes/flutter_web/lib/pages/notes/layout/1.welcome/note.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- **AspectRatio**:此组件强制其子组件保持特定的宽高比,确保内容在不同屏幕尺寸下都能保持一致的比例关系。
- **Container**: 虽然本身不是一个布局组件,但它提供了装饰、边距、填充等功能,结合其子组件可以实现复杂的布局效果。
- **ConstrainedBox&ConstrainedBox**:
- **ConstrainedBox**:
- **ConstrainedBox**:为子组件添加额外的大小限制,常用于在自定义布局中施加特定的宽高约束。
- 【场景】当你需要对子Widget施加尺寸上的约束,但允许其在一定范围内自适应时,使用ConstrainedBox
- **UnconstrainedBox**: 取消对其子组件的所有约束,使得子组件能自由根据其内容大小进行布局。
Expand Down
61 changes: 61 additions & 0 deletions packages/you_flutter/lib/src/better_ui.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

typedef _WidgetWarp = Widget Function(Widget child);

Expand Down Expand Up @@ -152,6 +153,49 @@ extension StyleExtension on Widget {
);
}

Widget constrainedBox$({required BoxConstraints constraints}) {
return ConstrainedBox(
constraints: constraints,
child: this,
);
}
Widget intrinsicWidth$({double? stepWidth, double? stepHeight}) {
return IntrinsicWidth(
stepWidth: stepWidth,
stepHeight: stepHeight,
child: this,
);
}

/// [width]If non-null, requires the child to have exactly this width.
/// [height]If non-null, requires the child to have exactly this height.
Widget sizedBox$({double? width, double? height}) {
return SizedBox(
width: width,
height: height,
child: this,
);
}

Widget sizedBoxExpand$() {
return SizedBox.expand(
child: this,
);
}

Widget sizedBoxShrink$() {
return SizedBox.shrink(
child: this,
);
}

Widget sizedBoxSquare$({double? dimension}) {
return SizedBox.square(
dimension: dimension,
child: this,
);
}

/// Warp a [FittedBox]
/// [fit]How to inscribe the child into the space allocated during layout.
/// [alignment]Defaults to [Alignment.center].
Expand All @@ -165,6 +209,23 @@ extension StyleExtension on Widget {
);
}


/// [minWidth]The minimum width constraint to give the child. Set this to null (the
/// default) to use the constraint from the parent instead.
/// [maxWidth]The maximum width constraint to give the child. Set this to null (the
/// default) to use the constraint from the parent instead.
/// [minHeight]The minimum height constraint to give the child. Set this to null (the
/// default) to use the constraint from the parent instead.
/// [maxHeight]The maximum height constraint to give the child. Set this to null (the
/// default) to use the constraint from the parent instead.
Widget overflowBox$({ AlignmentGeometry alignment = Alignment.center,double? minWidth,double? maxWidth, double? minHeight,double? maxHeight,OverflowBoxFit fit = OverflowBoxFit.max}) {
return OverflowBox(
fit: fit,
alignment: alignment,
child: this,
);
}

/// Warp a [Align]
Widget align$({Alignment alignment = Alignment.center, double? widthFactor, double? heightFactor}) {
return Align(alignment: alignment, widthFactor: widthFactor, heightFactor: heightFactor, child: this);
Expand Down
25 changes: 12 additions & 13 deletions packages/you_note_dart/lib/src/layouts/note_layout_style_1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ final class NoteLayoutStyle1 extends StatelessWidget {
}).toList();
return Row(
children: [
LimitedBox(maxWidth: 500, child: _NoteTreeView(uri)),
// IntrinsicWidth(child: _NoteTreeView(uri)),
_NoteTreeView(uri),
Flexible(child: ListView(children: pageContents)),
],
);
Expand All @@ -54,25 +55,23 @@ class _NoteTreeView extends StatelessWidget {
Widget build(BuildContext context) {
YouRouter router = YouRouter.of(context);

var routeWidgets = uri.to.root.toList().where((e) => !e.isLeaf || (e.isValid)).map((node) {
var validRoutes = uri.to.root.toList().where((e) => !e.isLeaf || (e.isValid));
var routeWidgets = validRoutes.map((node) {
String title = "▼ ${node.part}";
title = title.padLeft((node.level * 3) + title.length);

var click = () {
router.to(node.toUri());
};
return Padding(
// 缩进模仿树形
padding: EdgeInsets.only(left: 10),
// 一页一个链接
child: Align(
alignment: Alignment.centerLeft,
child: TextButton(onPressed: node.isValid ? click : null, child: Text(title)),
),
return Align(
alignment: Alignment.centerLeft,
child: TextButton(onPressed: node.isValid ? click : null, child: Text(title)),
);
});
return ListView(
children: [...routeWidgets],
);
return ConstrainedBox(
constraints: BoxConstraints.tightFor(width: 350),
child: ListView(
children: [...routeWidgets],
));
}
}

0 comments on commit 68064f9

Please sign in to comment.