Skip to content

Commit 0463676

Browse files
add md
1 parent d509a81 commit 0463676

File tree

5 files changed

+284
-0
lines changed

5 files changed

+284
-0
lines changed

source/flutter/widgets/ErrorWidget.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: 'ErrorWidget'
3+
description: '屏蔽错误页面组件'
4+
type: widgets
5+
---
6+
7+
## ErrorWidget
8+
9+
屏蔽错误页面组件,`ErrorWidget`的构造函数的参数是exception的对象,然后返回一个内容是exception message信息的RenderBox.
10+
11+
正常错误页面
12+
13+
![](http://img.laomengit.com/errorWidget1.png)
14+
15+
要想Flutter的错误页面显示成自定义的页面,只要设置`ErrorWidget``builder`就行
16+
17+
```dart
18+
ErrorWidget.builder = (FlutterErrorDetails flutterErrorDetails){
19+
print(flutterErrorDetails.toString());
20+
return Center(
21+
child: Text("Flutter 走神了"),
22+
);
23+
};
24+
```
25+
26+
27+
28+
ErrorWidget.builder 返回一个Widget,当Flutter出错的时候就会显示这个Widget。
29+
30+
![](http://img.laomengit.com/errorWidget2.png)
31+
32+
## ErrorWidget用法
33+
34+
ErrorWidget组件在build Widget的过程中调用。
35+
36+
案例
37+
38+
```dart
39+
Widget built;
40+
try {
41+
built = build();
42+
} catch (e, stack) {
43+
//ErrorWidget.builder
44+
built = ErrorWidget.builder(_debugReportException('building $this', e, stack));
45+
}
46+
47+
try {
48+
built = build();
49+
} catch (exception, stack) {
50+
//FlutterErrorDetails
51+
final FlutterErrorDetails details = FlutterErrorDetails(
52+
exception: exception,
53+
stack: stack,
54+
library: 'widgets library',
55+
context: 'attaching to the render tree'
56+
);
57+
FlutterError.reportError(details);
58+
final Widget error = ErrorWidget.builder(details);
59+
built = updateChild(null, error, _rootChildSlot);
60+
}
61+
62+
```
63+
64+
## 共建者供稿
65+
66+
本文由[**Rock**]()提供。
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+

source/flutter/widgets/IconTheme.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: 'IconTheme'
3+
description: 'icon 样式'
4+
type: widgets
5+
---
6+
7+
## IconTheme
8+
9+
用于应用栏图标的颜色,不透明度和大小。
10+
11+
```dart
12+
IconTheme({
13+
Key key,
14+
@required this.data,
15+
@required Widget child,
16+
})
17+
```
18+
19+
20+
21+
案例
22+
23+
```dart
24+
IconTheme(
25+
data: IconThemeData(color: Colors.blue, opacity: 3.0,size: 36),
26+
child: Container(
27+
padding: EdgeInsets.all(20.0),
28+
child: Icon(Icons.equalizer),
29+
),
30+
)
31+
```
32+
33+
![](http://img.laomengit.com/image-20200512061123076.png)
34+
35+
36+
37+
## 共建者供稿
38+
39+
本文由[**Rock**]()提供。
40+
41+
42+
43+
44+
45+
46+

source/flutter/widgets/OverflowBox.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: 'OverflowBox'
3+
description: '控件介绍'
4+
type: widgets
5+
---
6+
7+
## OverflowBox
8+
9+
溢出父容器显示,允许child超出父容器的范围显示
10+
11+
```dart
12+
OverflowBox({
13+
Key key,
14+
this.alignment = Alignment.center,//对齐方式。
15+
this.minWidth,//允许child的最小宽度。如果child宽度小于这个值,则按照最小宽度进行显示。
16+
this.maxWidth,//允许child的最大宽度。如果child宽度大于这个值,则按照最大宽度进行展示。
17+
this.minHeight,//允许child的最小高度。如果child高度小于这个值,则按照最小高度进行显示。
18+
this.maxHeight,//允许child的最大高度。如果child高度大于这个值,则按照最大高度进行展示。
19+
Widget child,
20+
})
21+
```
22+
23+
OverflowBox,允许child超出parent的范围显示,当然不用这个控件,也有很多种方式实现类似的效果。
24+
25+
- 当OverflowBox的最大尺寸大于child的时候,child可以完整显示,
26+
- 当其小于child的时候,则以最大尺寸为基准,当然,这个尺寸都是可以突破父节点的。。
27+
- 当最小以及最大宽高度,如果为null的时候,就取父节点的constraint代替。
28+
29+
案例
30+
31+
```dart
32+
Container(
33+
color: Colors.green,
34+
width: 200.0,
35+
height: 200.0,
36+
padding: const EdgeInsets.all(5.0),
37+
child: OverflowBox(
38+
alignment: Alignment.topLeft,
39+
maxWidth: 300.0,
40+
maxHeight: 500.0,
41+
child: Container(
42+
color: Color(0x33FF00FF),
43+
width: 400.0,
44+
height: 400.0,
45+
),
46+
),
47+
)
48+
49+
```
50+
51+
![](http://img.laomengit.com/overflowBox1.png)
52+
53+
## 共建者供稿
54+
55+
本文由[**Rock**]()提供。
56+
57+
58+
59+
60+
61+
62+
63+
64+

source/flutter/widgets/RotatedBox.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: 'RotatedBox'
3+
description: '旋转控件'
4+
type: widgets
5+
---
6+
7+
## RotatedBox
8+
9+
旋转盒子
10+
11+
```dart
12+
RotatedBox({
13+
Key key,
14+
@required this.quarterTurns,//旋转的次数,每次旋转的度数只能是90度的整数倍
15+
Widget child,
16+
})
17+
```
18+
19+
RotatedBox和Transform.rotate功能相似,它们都可以对子组件进行旋转变换,但是有一点不同:RotatedBox的变换是在layout阶段,会影响子组件的位置和大小
20+
21+
案例
22+
23+
```dart
24+
Row(
25+
mainAxisAlignment: MainAxisAlignment.center,
26+
children: <Widget>[
27+
DecoratedBox(
28+
decoration: BoxDecoration(color: Colors.red),
29+
//将Transform.rotate换成RotatedBox
30+
child: RotatedBox(
31+
quarterTurns: 1, //旋转90度(1/4圈)
32+
child: Text("Hello world"),
33+
),
34+
),
35+
Text("你好", style: TextStyle(color: Colors.green, fontSize: 18.0),)
36+
],
37+
),
38+
39+
```
40+
41+
![](http://img.laomengit.com/rotatedBox1.png)
42+
43+
44+
45+
46+
47+
由于`RotatedBox`是作用于layout阶段,所以子组件会旋转90度(而不只是绘制的内容),`decoration`会作用到子组件所占用的实际空间上,所以最终就是上图的效果
48+
49+
50+
51+
## 共建者供稿
52+
53+
本文由[**Rock**]()提供。
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: 'SizedOverflowBox'
3+
description: '控件介绍'
4+
type: widgets
5+
---
6+
7+
## SizedOverflowBox
8+
9+
是SizedBox与OverflowBox的结合体。一个特定大小的widget,但是会将它的原始约束传递给它的子组件,它可能会溢出。
10+
11+
```dart
12+
SizedOverflowBox({
13+
Key key,
14+
@required this.size,//固定的尺寸。
15+
this.alignment = Alignment.center,//对齐方式。
16+
Widget child,
17+
})
18+
```
19+
20+
SizedOverflowBox主要的布局行为有两点:
21+
22+
- 尺寸部分。通过将自身的固定尺寸,传递给child,来达到控制child尺寸的目的;
23+
- 超出部分。可以突破父节点尺寸的限制,超出部分也可以被渲染显示,与OverflowBox类似。
24+
25+
案例
26+
27+
```dart
28+
Container(
29+
color: Colors.blue[50],
30+
child: SizedOverflowBox(
31+
size: const Size(100.0, 100.0),
32+
alignment: AlignmentDirectional.bottomStart,
33+
child: Container(height: 50.0, width: 150.0, color: Colors.blue,),
34+
),
35+
)
36+
```
37+
38+
![](http://img.laomengit.com/sizedOverflowBox3.jpg)
39+
40+
41+
42+
## 共建者供稿
43+
44+
本文由[**Rock**]()提供。

0 commit comments

Comments
 (0)