Skip to content

Commit d6fb391

Browse files
committed
Wrap
1 parent 091fad8 commit d6fb391

File tree

6 files changed

+156
-1
lines changed

6 files changed

+156
-1
lines changed

docs/widget/regular/wrap/index.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## **Wrap**
2+
3+
>
4+
该控件以多个水平或垂直方向显示其子控件
5+
* 单行的Wrap和Row表现几乎一致,单列的Wrap和Column表现几乎一致,但是Row同Column系单行单列的,Wrap中行或列空间不足时,会自动换行
6+
7+
### 构造方法
8+
``` dart
9+
Wrap({
10+
Key key,
11+
this.direction = Axis.horizontal,
12+
this.alignment = WrapAlignment.start,
13+
this.spacing = 0.0,
14+
this.runAlignment = WrapAlignment.start,
15+
this.runSpacing = 0.0,
16+
this.crossAxisAlignment = WrapCrossAlignment.start,
17+
this.textDirection,
18+
this.verticalDirection = VerticalDirection.down,
19+
List<Widget> children = const <Widget>[],
20+
})
21+
```
22+
23+
### 属性介绍
24+
* direction:主轴的方向,默认为水平,值:Axis.horizontal/vertical
25+
* alignment:主轴方向上的对齐方式,默认为start, 值: WrapAlignment.start/center/end/spaceAround/spaceBetween/spaceEvenly
26+
* spacing:主轴方向上的间距。
27+
* runAlignment:run的对齐方式, 值: WrapAlignment.start/center/end/spaceAround/spaceBetween/spaceEvenly
28+
* runSpacing:run的间距。
29+
* crossAxisAlignment:交叉轴(crossAxis)方向上的对齐方式,值: WrapCrossAlignment.start/center/end
30+
* textDirection:文本方向, 值:TextDirection.ltr/rtl
31+
* verticalDirection:定义了children摆放顺序,默认是down,值: VerticalDirection.down/up

lib/widget/regular/constrainedbox/index.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'demo_expand.dart' as DemoExpand;
55

66
class Index extends StatefulWidget {
77
static String title = 'ConstrainedBox';
8-
static String originCodeUrl = '';
8+
static String originCodeUrl = 'https://docs.flutter.io/flutter/widgets/ConstrainedBox-class.html';
99
static String mdUrl = 'docs/widget/regular/constrainedbox/index.md';
1010
@override
1111
_IndexState createState() => _IndexState();

lib/widget/regular/index.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'center/index.dart' as Center;
88
import 'fittedbox/index.dart' as FittedBox;
99
import 'aspectratio/index.dart' as AspectRatio;
1010
import 'constrainedbox/index.dart' as ConstrainedBox;
11+
import 'wrap/index.dart' as Wrap;
1112

1213
const nameSpaces = '/regular_';
1314

@@ -56,6 +57,11 @@ List widgets = [
5657
widget: ConstrainedBox.Index(),
5758
code: 57709, // low_priority
5859
title: ConstrainedBox.Index.title
60+
),
61+
ItemInfo(
62+
widget: Wrap.Index(),
63+
code: 59385, // pages
64+
title: Wrap.Index.title
5965
)
6066
];
6167

lib/widget/regular/wrap/demo.dart

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 direction = Axis.horizontal;
10+
var directionValue = 'horizontal';
11+
var verticalDirection = VerticalDirection.down;
12+
var verticalDirectionValue = 'down';
13+
var spacing = 10.0;
14+
var runSpacing = 10.0;
15+
16+
@override
17+
Widget build(BuildContext context) {
18+
return Scaffold(
19+
appBar: AppBar(title: Text('Wrap'),),
20+
body: ListView(
21+
children: <Widget>[
22+
SizedBox(
23+
child: Text('点击下面值查看变化'),
24+
),
25+
Wrap(
26+
alignment: WrapAlignment.center,
27+
children: <Widget>[
28+
FlatButton(
29+
child: Text('direction:$directionValue', style: TextStyle(fontSize: 11.0),),
30+
onPressed: (){
31+
setState(() {
32+
direction == Axis.horizontal ? direction = Axis.vertical : direction = Axis.horizontal;
33+
directionValue == 'horizontal' ? directionValue = 'vertical' : directionValue = 'horizontal';
34+
});
35+
},
36+
),
37+
FlatButton(
38+
child: Text('verticalDirection:$verticalDirectionValue', style: TextStyle(fontSize: 11.0),),
39+
onPressed: (){
40+
setState(() {
41+
verticalDirection == VerticalDirection.up ? verticalDirection = VerticalDirection.down : verticalDirection = VerticalDirection.up;
42+
verticalDirectionValue == 'up' ? verticalDirectionValue = 'down' : verticalDirectionValue = 'up';
43+
});
44+
},
45+
),
46+
FlatButton(
47+
child: Text('spacing:$spacing', style: TextStyle(fontSize: 13.0),),
48+
onPressed: (){
49+
setState(() {
50+
spacing == 10 ? spacing = 15 : spacing = 10;
51+
});
52+
},
53+
),
54+
FlatButton(
55+
child: Text('runSpacing:$runSpacing', style: TextStyle(fontSize: 13.0),),
56+
onPressed: (){
57+
setState(() {
58+
runSpacing == 10 ? runSpacing = 15 : runSpacing = 10;
59+
});
60+
},
61+
)
62+
],
63+
),
64+
Container(
65+
width: double.infinity,
66+
height: 200,
67+
color: Theme.of(context).primaryColor,
68+
child: Wrap(
69+
direction: direction,
70+
alignment: WrapAlignment.center,
71+
spacing: spacing,
72+
runAlignment: WrapAlignment.center,
73+
runSpacing: runSpacing,
74+
crossAxisAlignment: WrapCrossAlignment.start,
75+
textDirection: TextDirection.ltr,
76+
verticalDirection: verticalDirection,
77+
children: List.generate(7, (index) {
78+
return Chip(
79+
avatar: CircleAvatar(
80+
backgroundColor: Theme.of(context).primaryColor,
81+
child: Text('E', style: TextStyle(fontSize: 20.0),),
82+
),
83+
label: Text('Efox$index'),
84+
);
85+
})
86+
),
87+
)
88+
],
89+
)
90+
);
91+
}
92+
}

lib/widget/regular/wrap/index.dart

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 = 'Wrap';
7+
static String originCodeUrl = 'https://docs.flutter.io/flutter/widgets/Wrap-class.html';
8+
static String mdUrl = 'docs/widget/regular/wrap/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
@@ -65,6 +65,7 @@ flutter:
6565
- docs/widget/regular/fittedbox/
6666
- docs/widget/regular/aspectratio/
6767
- docs/widget/regular/constrainedbox/
68+
- docs/widget/regular/wrap/
6869
# An image asset can refer to one or more resolution-specific "variants", see
6970
# https://flutter.io/assets-and-images/#resolution-aware.
7071

0 commit comments

Comments
 (0)