Skip to content

Commit ccceb14

Browse files
update listview demo
垂直listview里面有水平滑动的listview Demo
1 parent a1567ee commit ccceb14

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import 'package:flutter/material.dart';
2+
3+
// 垂直listview嵌套水平的listview
4+
class ListViewNestedDemo extends StatelessWidget {
5+
@override
6+
Widget build(BuildContext context) {
7+
return new MaterialApp(
8+
title: new Text(
9+
'垂直listview嵌套水平的listview Demo',
10+
style: new TextStyle(fontSize: 15.0),
11+
),
12+
theme: new ThemeData(
13+
primarySwatch: Colors.blue,
14+
),
15+
home: new ListViewNested(),
16+
);
17+
}
18+
}
19+
20+
class ListViewNested extends StatelessWidget {
21+
@override
22+
Widget build(BuildContext context) {
23+
return new Scaffold(
24+
appBar: new AppBar(
25+
title: new Text(
26+
'垂直listview嵌套水平的listview Demo',
27+
style: new TextStyle(fontSize: 15.0),
28+
),
29+
),
30+
// body: buildListView(),
31+
body: buildListView2(),
32+
);
33+
}
34+
35+
// ListView -> SizedBox -> ListView -> 然后就是具体的组件
36+
Widget buildListView() {
37+
return new ListView(
38+
children: [
39+
new SizedBox(
40+
height: 100.0,
41+
child: ListView(
42+
// 设置滑动方向是水平方向
43+
scrollDirection: Axis.horizontal,
44+
children: <Widget>[
45+
new FlutterLogo(colors: Colors.pink, size: 100),
46+
new FlutterLogo(colors: Colors.teal, size: 100),
47+
new FlutterLogo(colors: Colors.brown, size: 100),
48+
new FlutterLogo(colors: Colors.lightBlue, size: 100),
49+
new FlutterLogo(colors: Colors.green, size: 100),
50+
new FlutterLogo(colors: Colors.pink, size: 100),
51+
new FlutterLogo(colors: Colors.teal, size: 100),
52+
new FlutterLogo(colors: Colors.brown, size: 100),
53+
new FlutterLogo(colors: Colors.lightBlue, size: 100),
54+
new FlutterLogo(colors: Colors.green, size: 100),
55+
],
56+
),
57+
),
58+
new FlutterLogo(colors: Colors.pink, size: 100),
59+
new FlutterLogo(colors: Colors.teal, size: 100),
60+
new FlutterLogo(colors: Colors.brown, size: 100),
61+
new FlutterLogo(colors: Colors.lightBlue, size: 100),
62+
new FlutterLogo(colors: Colors.green, size: 100),
63+
new FlutterLogo(colors: Colors.pink, size: 100),
64+
new FlutterLogo(colors: Colors.teal, size: 100),
65+
new FlutterLogo(colors: Colors.brown, size: 100),
66+
new FlutterLogo(colors: Colors.lightBlue, size: 100),
67+
new FlutterLogo(colors: Colors.green, size: 100),
68+
],
69+
);
70+
}
71+
72+
73+
// ListView -> SizedBox -> SingleChildScrollView -> Row -> 然后就是具体的组件
74+
Widget buildListView2() {
75+
// 纵向滑动的listview
76+
return new ListView(
77+
children: [
78+
new SizedBox(
79+
height: 100.0,
80+
child: new SingleChildScrollView(
81+
// 设置滑动方向是水平方向
82+
scrollDirection: Axis.horizontal,
83+
child: new Row(
84+
children: <Widget>[
85+
new FlutterLogo(colors: Colors.pink, size: 100),
86+
new FlutterLogo(colors: Colors.teal, size: 100),
87+
new FlutterLogo(colors: Colors.brown, size: 100),
88+
new FlutterLogo(colors: Colors.lightBlue, size: 100),
89+
new FlutterLogo(colors: Colors.green, size: 100),
90+
new FlutterLogo(colors: Colors.pink, size: 100),
91+
new FlutterLogo(colors: Colors.teal, size: 100),
92+
new FlutterLogo(colors: Colors.brown, size: 100),
93+
new FlutterLogo(colors: Colors.lightBlue, size: 100),
94+
new FlutterLogo(colors: Colors.green, size: 100),
95+
],
96+
),
97+
),
98+
),
99+
new FlutterLogo(colors: Colors.pink, size: 100),
100+
new FlutterLogo(colors: Colors.teal, size: 100),
101+
new FlutterLogo(colors: Colors.brown, size: 100),
102+
new FlutterLogo(colors: Colors.lightBlue, size: 100),
103+
new FlutterLogo(colors: Colors.green, size: 100),
104+
new FlutterLogo(colors: Colors.pink, size: 100),
105+
new FlutterLogo(colors: Colors.teal, size: 100),
106+
new FlutterLogo(colors: Colors.brown, size: 100),
107+
new FlutterLogo(colors: Colors.lightBlue, size: 100),
108+
new FlutterLogo(colors: Colors.green, size: 100),
109+
],
110+
);
111+
}
112+
}

0 commit comments

Comments
 (0)