Flutter 组件 GridView
xxxixxxx
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

List<Widget> _getData() {
var widgetList = List<Widget>();
for (var i = 0; i < 30; i++) {
var c = Container(
// alignment: Alignment.topCenter,
color: Colors.green[100],
child: Column(
children: [
Image(image: Assets.images.cat),
SizedBox(
height: 12,
),
Text(
'哈哈哈 $i',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 24),
),
],
),
);
widgetList.add(c);
}
return widgetList;
}

GridView.count

1
2
3
4
5
6
7
8
9
GridView.count(
scrollDirection: Axis.vertical,
padding: EdgeInsets.fromLTRB(16, 20, 16, 20),
crossAxisCount: 2,
crossAxisSpacing: 8,
mainAxisSpacing: 10,
childAspectRatio: 0.8,
children: this._getData(),
);

GridView.builder

1
2
3
4
5
6
7
8
9
10
11
12
13
GridView.builder(
padding: EdgeInsets.all(10),
itemCount: _getData().length,
itemBuilder: (context, index) {
return _getData()[index];
},
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.8,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
),
);
  • Post title:Flutter 组件 GridView
  • Post author:xxxixxxx
  • Create time:2020-12-29 10:11:00
  • Post link:https://xxxixxx.github.io/2020/12/29/400-Flutter组件GridView/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
 Comments