Skip to content

Commit c218ec1

Browse files
committed
center
1 parent c3490ce commit c218ec1

File tree

7 files changed

+141
-1
lines changed

7 files changed

+141
-1
lines changed

docs/widget/regular/center/code.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
### Center
2+
3+
``` dart
4+
import 'package:flutter/material.dart';
5+
6+
class Index extends StatefulWidget {
7+
@override
8+
_IndexState createState() => _IndexState();
9+
}
10+
11+
class _IndexState extends State<Index> {
12+
var heightFactor = 2.0;
13+
@override
14+
Widget build(BuildContext context) {
15+
return Scaffold(
16+
appBar: AppBar(title: Text('Center Demo'),),
17+
body: Column(
18+
children: <Widget>[
19+
Center(
20+
heightFactor: heightFactor,
21+
widthFactor: double.infinity,
22+
child: Container(
23+
width: 120.0,
24+
height: 120.0,
25+
decoration: BoxDecoration(
26+
image: DecorationImage(
27+
image: NetworkImage('http://sucimg.itc.cn/avatarimg/55d21fdc4b8d4838bef0da94ada78cab_1501139484387')
28+
)
29+
),
30+
),
31+
),
32+
FlatButton(
33+
child: Text('heightFactor: $heightFactor', style: TextStyle(fontSize: 20.0),),
34+
onPressed: (){
35+
setState(() {
36+
heightFactor == 1.0 ? heightFactor = 2.0 : heightFactor = 1.0;
37+
});
38+
},
39+
)
40+
],
41+
)
42+
);
43+
}
44+
}
45+
46+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## **Center**
2+
3+
>
4+
将child置于中心的控件
5+
* Center继承自Align,只不过是将alignment设置为Alignment.center
6+
7+
### 构造方法
8+
``` dart
9+
Center({
10+
Key key,
11+
double widthFactor,
12+
double heightFactor,
13+
Widget child
14+
})
15+
```
16+
17+
### 属性介绍
18+
* widthFactor/heightFactor: 当widthFactor和heightFactor为null的时候,Center会调整到child的尺寸,当widthFactor或者heightFactor不为null的时候,Center会根据factor属性,扩展自己的尺寸,例如设置heightFactor为2.0的时候,那么,Center的高度将会是child的两倍
19+
* child: Center中的内容widget

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class MainAppState extends State<MainApp> {
7777
),
7878
accentColor: Colors.grey,
7979
accentColorBrightness: Brightness.light,
80-
primaryColor: Colors.grey.shade50, // appbar背景
80+
primaryColor: Colors.redAccent, // appbar背景
8181
scaffoldBackgroundColor: Colors.grey.shade50, // 整体的scaffold背景颜色
8282
),
8383
onGenerateRoute: FluroRouter.router.generator,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'package:flutter/material.dart';
2+
3+
class Index extends StatefulWidget {
4+
@override
5+
_IndexState createState() => _IndexState();
6+
}
7+
8+
class _IndexState extends State<Index> {
9+
var heightFactor = 2.0;
10+
@override
11+
Widget build(BuildContext context) {
12+
return Scaffold(
13+
appBar: AppBar(title: Text('Center Demo'),),
14+
body: Column(
15+
children: <Widget>[
16+
Center(
17+
heightFactor: heightFactor,
18+
widthFactor: double.infinity,
19+
child: Container(
20+
width: 120.0,
21+
height: 120.0,
22+
decoration: BoxDecoration(
23+
image: DecorationImage(
24+
image: NetworkImage('http://sucimg.itc.cn/avatarimg/55d21fdc4b8d4838bef0da94ada78cab_1501139484387')
25+
)
26+
),
27+
),
28+
),
29+
FlatButton(
30+
child: Text('heightFactor: $heightFactor', style: TextStyle(fontSize: 20.0),),
31+
onPressed: (){
32+
setState(() {
33+
heightFactor == 1.0 ? heightFactor = 2.0 : heightFactor = 1.0;
34+
});
35+
},
36+
)
37+
],
38+
)
39+
);
40+
}
41+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:efox_flutter/components/widgetComp.dart' as WidgetComp;
3+
import 'demo.dart' as Demo;
4+
5+
class Index extends StatefulWidget {
6+
static String name = 'Center';
7+
static String originCodeUrl = 'https://docs.flutter.io/flutter/widgets/Center-class.html';
8+
static String codeUrl = 'docs/widget/regular/center/code.md';
9+
static String mdUrl = 'docs/widget/regular/center/index.md';
10+
@override
11+
_IndexState createState() => _IndexState();
12+
}
13+
14+
class _IndexState extends State<Index> {
15+
@override
16+
Widget build(BuildContext context) {
17+
return WidgetComp.Index(
18+
name: Index.name,
19+
codeUrl: Index.codeUrl,
20+
originCodeUrl: Index.originCodeUrl,
21+
mdUrl: Index.mdUrl,
22+
demoChild: <Widget>[
23+
Demo.Index()
24+
],
25+
);
26+
}
27+
}

lib/widget/regular/index.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'column/index.dart' as Column;
44
import 'container/index.dart' as Container;
55
import 'padding/index.dart' as Padding;
66
import 'align/index.dart' as Align;
7+
import 'center/index.dart' as Center;
78

89
const nameSpaces = '/regular_';
910

@@ -32,6 +33,11 @@ List widgets = [
3233
widget: Align.Index(),
3334
code: 57917, // format_indent_decrease
3435
name: Align.Index.name
36+
),
37+
ItemInfo(
38+
widget: Center.Index(),
39+
code: 57932, // format_indent_decrease
40+
name: Center.Index.name
3541
)
3642
];
3743

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ flutter:
6161
- docs/widget/regular/container/
6262
- docs/widget/regular/padding/
6363
- docs/widget/regular/align/
64+
- docs/widget/regular/center/
6465
# An image asset can refer to one or more resolution-specific "variants", see
6566
# https://flutter.io/assets-and-images/#resolution-aware.
6667

0 commit comments

Comments
 (0)