-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathview_demo.dart
166 lines (156 loc) · 4.03 KB
/
view_demo.dart
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import 'package:flutter/material.dart';
import 'package:pro_flutter/demo/model/post.dart';
class ViewDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GridViewBuildDemo();
}
}
class GridViewBuildDemo extends StatelessWidget {
Widget _gridItemBuilder(BuildContext context, int index) {
return Container(
child: Image.network(
posts[index].imageUrl,
fit: BoxFit.cover,
),
);
}
@override
Widget build(BuildContext context) {
return GridView.builder(
padding: EdgeInsets.all(8.0),
itemCount: posts.length,
itemBuilder: _gridItemBuilder,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 8.0,
mainAxisSpacing: 8.0,
),
);
}
}
class GridViewExtentDemo extends StatelessWidget {
List<Widget> _buildTiles(int length) {
return List.generate(length, (int index) {
return Container(
color: Colors.grey,
alignment: Alignment(0.0, 0.0),
child: Text(
'item ${index + 1}',
style: TextStyle(fontSize: 20.0, color: Colors.grey[100]),
),
);
});
}
@override
Widget build(BuildContext context) {
return GridView.extent(
maxCrossAxisExtent: 160.0,
crossAxisSpacing: 8.0,
mainAxisSpacing: 8.0,
children: _buildTiles(50),
);
}
}
class GridViewCountDemo extends StatelessWidget {
List<Widget> _buildTiles(int length) {
return List.generate(length, (int index) {
return Container(
color: Colors.grey,
alignment: Alignment(0.0, 0.0),
child: Text(
'item ${index + 1}',
style: TextStyle(fontSize: 20.0, color: Colors.grey[100]),
),
);
});
}
@override
Widget build(BuildContext context) {
return GridView.count(
crossAxisCount: 3,
crossAxisSpacing: 8.0,
mainAxisSpacing: 8.0,
children: _buildTiles(50),
);
}
}
class PageBuildViewDemo extends StatelessWidget {
Widget _pageItemBuilder(BuildContext context, int index) {
return Stack(
children: <Widget>[
SizedBox.expand(
child: Image.network(
posts[index].imageUrl,
fit: BoxFit.cover,
),
),
Positioned(
bottom: 20.0,
left: 20.0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
posts[index].title,
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(
posts[index].author,
style: TextStyle(fontWeight: FontWeight.w100),
),
],
),
),
],
);
}
@override
Widget build(BuildContext context) {
return PageView.builder(
itemCount: posts.length,
itemBuilder: _pageItemBuilder,
);
}
}
class PageViewDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PageView(
// pageSnapping: false,
// scrollDirection: Axis.vertical,
onPageChanged: (currentPage) => debugPrint('$currentPage'),
controller: PageController(
initialPage: 1,
keepPage: false,
viewportFraction: 0.85,
),
children: <Widget>[
Container(
color: Colors.amberAccent[100],
alignment: Alignment(0.0, 0.0),
child: Text(
'One',
style: TextStyle(fontSize: 23.0, color: Colors.black),
),
),
Container(
color: Colors.blueAccent[100],
alignment: Alignment(0.0, 0.0),
child: Text(
'Two',
style: TextStyle(fontSize: 23.0, color: Colors.black),
),
),
Container(
color: Colors.blueGrey[100],
alignment: Alignment(0.0, 0.0),
child: Text(
'Three',
style: TextStyle(fontSize: 23.0, color: Colors.black),
),
),
],
);
}
}