Skip to content

Commit cf76656

Browse files
committed
Stack
1 parent afcebfc commit cf76656

File tree

6 files changed

+164
-1
lines changed

6 files changed

+164
-1
lines changed

docs/widget/regular/flow/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
实现优化流式布局以使用流布局的控件
55
* 实现较为复杂,一般可通过Wrap来替换实现
66

7-
## 构造方法
7+
### 构造方法
88
``` dart
99
Flow({
1010
Key key,

docs/widget/regular/stack/index.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## **Stack**
2+
3+
>
4+
该Widget将子控件相对于其边框进行定位
5+
* Stack的布局行为,根据child是positioned节点还是non-positioned节点来区分
6+
* 对于positioned的子节点,它们的位置会根据所设置的top、bottom、right以及left属性来确定,这几个值都是相对于Stack的左上角;
7+
* 对于non-positioned的子节点,它们会根据Stack的aligment来设置位置。
8+
* 对应child的顺序,第一个child会被绘制在最低端
9+
10+
### 构造方法
11+
``` dart
12+
Stack({
13+
Key key,
14+
this.alignment = AlignmentDirectional.topStart,
15+
this.textDirection,
16+
this.fit = StackFit.loose,
17+
this.overflow = Overflow.clip,
18+
List<Widget> children = const <Widget>[],
19+
})
20+
```
21+
22+
### 属性介绍
23+
* alignment: 对齐方式,默认是topLeft
24+
* textDirection:文本方向,不常用
25+
* fit: 默认loose
26+
* loose:子节点尺寸可以从min到max
27+
* expand:子节点尽可能占用空间
28+
* passthrough: 不改变子节点约束
29+
* overflow:超过部分是否裁切,Overflow.clip/visible
30+
* children: Stack中的内容Widget
31+

lib/widget/regular/index.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'constrainedbox/index.dart' as ConstrainedBox;
1111
import 'wrap/index.dart' as Wrap;
1212
import 'table/index.dart' as Table;
1313
import 'flow/index.dart' as Flow;
14+
import 'stack/index.dart' as Stack;
1415

1516
const nameSpaces = '/regular_';
1617

@@ -74,6 +75,11 @@ List widgets = [
7475
widget: Flow.Index(),
7576
code: 58915, // sd_card
7677
title: Flow.Index.title
78+
),
79+
ItemInfo(
80+
widget: Stack.Index(),
81+
code: 57795, // settings_system_daydream
82+
title: Stack.Index.title
7783
)
7884
];
7985

lib/widget/regular/stack/demo.dart

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
List alignment = [
10+
Alignment.topLeft,
11+
Alignment.topCenter,
12+
Alignment.topRight,
13+
Alignment.centerLeft,
14+
Alignment.center,
15+
Alignment.centerRight,
16+
Alignment.bottomLeft,
17+
Alignment.bottomCenter,
18+
Alignment.bottomRight
19+
];
20+
int alignmentIndex = 5;
21+
22+
@override
23+
Widget build(BuildContext context) {
24+
return Scaffold(
25+
appBar: AppBar(title: Text('AppBar'),),
26+
body: ListView(
27+
children: <Widget>[
28+
SizedBox(
29+
child: Text('修改alignment的值,non-positined节点会改变位置'),
30+
),
31+
Wrap(
32+
alignment: WrapAlignment.spaceBetween,
33+
children: List.generate(9, (index) {
34+
return FlatButton(
35+
child: Text('${alignment[index]}', style: TextStyle(fontSize: 11.0),),
36+
onPressed: (){
37+
setState(() {
38+
alignmentIndex = index;
39+
});
40+
},
41+
);
42+
}),
43+
),
44+
StackDemo(alignmentValue: alignment[alignmentIndex],)
45+
],
46+
),
47+
);
48+
}
49+
}
50+
51+
class StackDemo extends StatelessWidget {
52+
var alignmentValue;
53+
StackDemo({Key key, @required this.alignmentValue}):super(key: key);
54+
55+
@override
56+
Widget build(BuildContext context) {
57+
return Stack(
58+
textDirection: TextDirection.ltr,
59+
fit: StackFit.loose,
60+
overflow: Overflow.clip,
61+
alignment: alignmentValue,
62+
children: <Widget>[
63+
AspectRatio(
64+
aspectRatio: 16/9,
65+
child: Image.network(
66+
'http://pic1.win4000.com/wallpaper/2019-01-31/5c52bf7fdc959_270_185.jpg',
67+
fit: BoxFit.cover
68+
),
69+
),
70+
Positioned(
71+
top: 32.0,
72+
left: 32.0,
73+
child: Column(
74+
crossAxisAlignment: CrossAxisAlignment.start,
75+
children: <Widget>[
76+
Text(
77+
'欢聚时代',
78+
style: TextStyle(
79+
fontSize: 20.0,
80+
color: Colors.red,
81+
fontWeight: FontWeight.bold
82+
),
83+
),
84+
Text(
85+
'Efox Team',
86+
style: TextStyle(
87+
fontSize: 14.0,
88+
color: Colors.redAccent
89+
),
90+
)
91+
],
92+
),
93+
),
94+
SizedBox(
95+
child: Icon(Icons.ac_unit, color: Theme.of(context).primaryColor, size: 32.0,),
96+
)
97+
]
98+
);
99+
}
100+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 title = 'Stack';
7+
static String originCodeUrl = 'https://docs.flutter.io/flutter/widgets/Stack-class.html';
8+
static String mdUrl = 'docs/widget/regular/stack/index.md';
9+
@override
10+
_IndexState createState() => _IndexState();
11+
}
12+
13+
class _IndexState extends State<Index> {
14+
@override
15+
Widget build(BuildContext context) {
16+
return WidgetComp.Index(
17+
title: Index.title,
18+
originCodeUrl: Index.originCodeUrl,
19+
mdUrl: Index.mdUrl,
20+
demoChild: <Widget>[
21+
Demo.Index()
22+
],
23+
);
24+
}
25+
}

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ flutter:
6969
- docs/widget/regular/wrap/
7070
- docs/widget/regular/table/
7171
- docs/widget/regular/flow/
72+
- docs/widget/regular/stack/
7273
# An image asset can refer to one or more resolution-specific "variants", see
7374
# https://flutter.io/assets-and-images/#resolution-aware.
7475

0 commit comments

Comments
 (0)