Skip to content

Commit 2a3206e

Browse files
committed
container
1 parent ae19fd3 commit 2a3206e

File tree

6 files changed

+164
-4
lines changed

6 files changed

+164
-4
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## **Container**
2+
3+
>
4+
一个常用的widget,它结合了常见的绘画,定位和大小调整
5+
6+
### 构造方法
7+
```
8+
Container({
9+
Key key,
10+
this.alignment,
11+
this.padding,
12+
Color color,
13+
Decoration decoration,
14+
this.foregroundDecoration,
15+
double width,
16+
double height,
17+
BoxConstraints constraints,
18+
this.margin,
19+
this.transform,
20+
this.child,
21+
})
22+
```
23+
24+
### 属性介绍
25+
* alignment:控制child的对齐方式,如果container或者container父节点尺寸大于child的尺寸,这个属性设置会起作用,有很多种对齐方式
26+
* padding:decoration内部的空白区域,如果有child的话,child位于padding内部。padding与margin的不同之处在于,padding是包含在content内,而margin则是外部边界,设置点击事件的话,padding区域会响应,而margin区域不会响应
27+
* color:用来设置container背景色,如果foregroundDecoration设置的话,可能会遮盖color效果
28+
* decoration:绘制在child后面的装饰,设置了decoration的话,就不能设置color属性,否则会报错,此时应该在decoration中进行颜色的设置
29+
* foregroundDecoration:绘制在child前面的装饰
30+
* width:container的宽度,设置为double.infinity可以强制在宽度上撑满,不设置,则根据child和父节点两者一起布局
31+
* height:container的高度,设置为double.infinity可以强制在高度上撑满
32+
* constraints:添加到child上额外的约束条件
33+
* margin:围绕在decoration和child之外的空白区域,不属于内容区域
34+
* transform:设置container的变换矩阵,类型为Matrix4
35+
* child:container中的内容widget

lib/widget/regular/column/index.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ String mdUrl = 'docs/widget/regular/column/index.md';
1010

1111
class Index extends StatefulWidget {
1212
static String name = 'Column';
13-
static String routerName = 'coloumn';
13+
static String routerName = 'column';
1414

1515
@override
1616
_IndexState createState() => new _IndexState();
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import 'package:flutter/material.dart';
2+
3+
class Index extends StatelessWidget {
4+
@override
5+
Widget build(BuildContext context) {
6+
return Scaffold(
7+
appBar: AppBar(title: Text('Container Demo'),),
8+
body: ListView(
9+
children: <Widget>[
10+
Center(
11+
child: Container(
12+
child: Text('Hello', style: TextStyle(fontSize: 20.0),),
13+
width: 80.0,
14+
height: 80.0,
15+
margin: const EdgeInsets.all(10.0),
16+
padding: const EdgeInsets.all(10.0),
17+
// color: const Color(0xfff48Fb1),
18+
alignment: Alignment.center,
19+
decoration: BoxDecoration(
20+
color: const Color(0xfff48Fb1),
21+
border: Border.all(width: 2.0, color: Colors.redAccent),
22+
borderRadius: BorderRadius.circular(10.0)
23+
),
24+
),
25+
),
26+
Center(
27+
child: Container(
28+
child: Text(
29+
'Hello World',
30+
style: Theme.of(context).textTheme.display1.copyWith(color: Colors.black),
31+
),
32+
// width: 200.0,
33+
// height: 200.0,
34+
// color: Colors.green,
35+
margin: const EdgeInsets.all(30.0),
36+
padding: const EdgeInsets.all(10.0),
37+
alignment: Alignment.center,
38+
decoration: BoxDecoration(
39+
border: Border.all(width: 2.0, color: Colors.red),
40+
color: Colors.grey,
41+
borderRadius: BorderRadius.all(Radius.circular(20.0)),
42+
image: DecorationImage(
43+
image: NetworkImage('http://sucimg.itc.cn/avatarimg/55d21fdc4b8d4838bef0da94ada78cab_1501139484387'),
44+
centerSlice: Rect.fromLTRB(270.0, 180.0, 1360.0, 730.0),
45+
// fit: BoxFit.cover
46+
)
47+
),
48+
constraints: BoxConstraints.expand(
49+
height: Theme.of(context).textTheme.display1.fontSize * 1.1 + 200.0
50+
),
51+
foregroundDecoration: BoxDecoration(
52+
image: DecorationImage(
53+
image: NetworkImage('https://www.example.com/images/frame.png'),
54+
centerSlice: Rect.fromLTRB(270.0, 180.0, 1360.0, 730.0),
55+
)
56+
),
57+
transform: Matrix4.rotationZ(0.1),
58+
),
59+
)
60+
],
61+
)
62+
);
63+
}
64+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:efox_flutter/components/widgetComp.dart' as WidgetComp;
3+
import 'package:efox_flutter/utils/file.dart' as FileUitls;
4+
import 'demo.dart' as Demo;
5+
6+
String originCodeUrl = 'https://docs.flutter.io/flutter/widgets/Container-class.html';
7+
String codeUrl = 'docs/widget/regular/container/code.md';
8+
String mdUrl = 'docs/widget/regular/container/index.md';
9+
10+
class Index extends StatefulWidget {
11+
static String name = 'Container';
12+
static String routerName = 'container';
13+
14+
@override
15+
_IndexState createState() => _IndexState();
16+
}
17+
18+
class _IndexState extends State<Index> {
19+
bool loading = true;
20+
String ___MD___ = mdUrl;
21+
22+
@override
23+
void initState() {
24+
// TODO: implement initState
25+
super.initState();
26+
this.initMd();
27+
}
28+
29+
initMd() async {
30+
String mdStr = await FileUitls.readLocaleFile(___MD___);
31+
setState(() {
32+
this.___MD___ = mdStr;
33+
loading = false;
34+
});
35+
}
36+
37+
@override
38+
Widget build(BuildContext context) {
39+
return WidgetComp.Index(
40+
name: Index.name,
41+
codeUrl: codeUrl,
42+
originCodeUrl: originCodeUrl,
43+
mdUrl: mdUrl,
44+
modelChild: (context, child, model) {
45+
return [
46+
___MD___
47+
];
48+
},
49+
demoChild: <Widget>[
50+
Demo.Index()
51+
],
52+
);
53+
}
54+
}

lib/widget/regular/index.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
import 'package:efox_flutter/store/objects/widget_info.dart';
22
import 'row/index.dart' as Row;
33
import 'column/index.dart' as Column;
4+
import 'container/index.dart' as Container;
45

56
const nameSpaces = '/Regular_';
67

78
List widgets = [
89
ItemInfo(
910
routerName: nameSpaces + Row.Index.routerName,
1011
widget: Row.Index(),
11-
code: 59692,
12+
code: 59702, // calendar_view_day
1213
name: Row.Index.name,
1314
),
1415
ItemInfo(
1516
routerName: nameSpaces + Column.Index.routerName,
1617
widget: Column.Index(),
17-
code: 59692,
18+
code: 59692, // accessibility_new
1819
name: Column.Index.name
20+
),
21+
ItemInfo(
22+
routerName: nameSpaces + Container.Index.routerName,
23+
widget: Container.Index(),
24+
code: 60219, // ac_unit
25+
name: Container.Index.name
1926
)
2027
];
2128

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ flutter:
5757
- locale/
5858
- docs/widget/scrollview/gridview/
5959
- docs/widget/regular/row/
60-
- docs/widget/regular/column/
60+
- docs/widget/regular/
6161
# An image asset can refer to one or more resolution-specific "variants", see
6262
# https://flutter.io/assets-and-images/#resolution-aware.
6363

0 commit comments

Comments
 (0)