-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxAbout.dart
More file actions
81 lines (77 loc) · 3.01 KB
/
BoxAbout.dart
File metadata and controls
81 lines (77 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import 'package:flutter/material.dart';
import 'package:flutter_starter_notes/component/CommonTitle.dart';
class BoxAbout extends StatelessWidget {
BoxAbout({Key key, this.title});
final String title;
Widget redBox = DecoratedBox(
decoration: BoxDecoration(color: Colors.red),
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
CommonTitle('ConstrainedBox 介绍'),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(16),
child: Text("ConstrainedBox用于对其子widget添加额外的约束。"),
),
CommonTitle('ConstrainedBox 例子'),
ConstrainedBox(
constraints: BoxConstraints(
minWidth: double.infinity, //宽度尽可能大
minHeight: 50.0 //最小高度为50像素
),
child: Container(height: 5.0, child: redBox),
),
CommonTitle('ConstrainedBox 多重限制'),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(16),
child: Text("有多重限制时,对于minWidth和minHeight来说,是取父子中相应数值较大的。"),
),
CommonTitle('ConstrainedBox 多重限制例子'),
ConstrainedBox(
constraints: BoxConstraints(minWidth: 60.0, minHeight: 60.0),
//父
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: 90.0, minHeight: 20.0),
//子
child: redBox,
)),
Divider(color: Colors.white,),
ConstrainedBox(
constraints: BoxConstraints(minWidth: 90.0, minHeight: 20.0),
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: 60.0, minHeight: 60.0),
child: redBox,
)),
CommonTitle('UnconstrainedBox 的使用'),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(16),
child: Text(
"UnconstrainedBox不会对子Widget产生任何限制,它允许其子Widget按照其本身大小绘制。一般情况下,我们会很少直接使用此widget,但在\"去除\"多重限制的时候也许会有帮助"),
),
ConstrainedBox(
constraints: BoxConstraints(minWidth: 60.0, minHeight: 100.0),
//父
child: UnconstrainedBox(
//“去除”父级限制
child: ConstrainedBox(
constraints:
BoxConstraints(minWidth: 90.0, minHeight: 20.0), //子
child: redBox,
),
))
],
),
),
);
}
}