-
Notifications
You must be signed in to change notification settings - Fork 701
/
main.dart
370 lines (351 loc) · 11.3 KB
/
main.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'src/ExampleCustom.dart';
import 'src/config.dart';
import 'src/ExampleSwiperInScrollView.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
Widget buildHome() {
return new Scaffold(
appBar: new AppBar(
title: new Text(""),
),
body: new Container(
color: Colors.black87,
child: new Column(
children: <Widget>[
new SizedBox(
height: 300.0,
child: Swiper(
layout: SwiperLayout.TINDER,
itemWidth: 300.0,
itemHeight: 200.0,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
return new Container(
color: Colors.grey,
child: new Center(
child: new Text("$index"),
),
);
},
itemCount: 10),
)
],
),
),
);
}
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Swiper'),
//home: buildHome() ,
routes: {
'/example01': (BuildContext context) => new ExampleHorizontal(),
'/example02': (BuildContext context) => new ExampleVertical(),
'/example03': (BuildContext context) => new ExampleFraction(),
'/example04': (BuildContext context) => new ExampleCustomPagination(),
'/example05': (BuildContext context) => new ExamplePhone(),
'/example06': (BuildContext context) => new ScaffoldWidget(
child: new ExampleSwiperInScrollView(), title: "ScrollView"),
'/example07': (BuildContext context) => new ScaffoldWidget(
child: new ExampleCustom(),
title: "Custom All",
)
},
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<Widget> render(BuildContext context, List children) {
return ListTile
.divideTiles(
context: context,
tiles: children.map((dynamic data) {
return buildListTile(context, data[0], data[1], data[2]);
}))
.toList();
}
Widget buildListTile(
BuildContext context, String title, String subtitle, String url) {
return new ListTile(
onTap: () {
Navigator.of(context).pushNamed(url);
},
isThreeLine: true,
dense: false,
leading: null,
title: new Text(title),
subtitle: new Text(subtitle),
trailing: new Icon(
Icons.arrow_right,
color: Colors.blueAccent,
),
);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: Text(widget.title),
),
body: new ListView(
children: render(context, [
["Horizontal", "Scroll Horizontal", "/example01"],
["Vertical", "Scroll Vertical", "/example02"],
["Fraction", "Fraction style", "/example03"],
["Custom Pagination", "Custom Pagination", "/example04"],
["Phone", "Phone view", "/example05"],
["ScrollView ", "In a ScrollView", "/example06"],
["Custom", "Custom all properties", "/example07"]
]),
),
);
}
}
const List<String> titles = [
"Flutter Swiper is awosome",
"Really nice",
"Yeap"
];
class ExampleHorizontal extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text("ExampleHorizontal"),
),
body: new Swiper(
itemBuilder: (BuildContext context, int index) {
return new Image.asset(
images[index],
fit: BoxFit.fill,
);
},
autoplay: true,
itemCount: images.length,
reverse: false,
pagination: new SwiperPagination(),
control: new SwiperControl(),
));
}
}
class ExampleVertical extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text("ExampleVertical"),
),
body: new Swiper(
itemBuilder: (BuildContext context, int index) {
return new Image.asset(
images[index],
fit: BoxFit.fill,
);
},
autoplay: true,
itemCount: images.length,
reverse: false,
scrollDirection: Axis.vertical,
pagination: new SwiperPagination(alignment: Alignment.centerRight),
control: new SwiperControl(),
));
}
}
class ExampleFraction extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: Text("ExampleFraction"),
),
body: new Column(
children: <Widget>[
Expanded(
child: new Swiper(
itemBuilder: (BuildContext context, int index) {
return new Image.asset(
images[index],
fit: BoxFit.fill,
);
},
autoplay: true,
itemCount: images.length,
reverse: false,
pagination:
new SwiperPagination(builder: SwiperPagination.fraction),
control: new SwiperControl(),
)),
Expanded(
child: new Swiper(
itemBuilder: (BuildContext context, int index) {
return new Image.asset(
images[index],
fit: BoxFit.fill,
);
},
autoplay: true,
itemCount: images.length,
reverse: false,
scrollDirection: Axis.vertical,
pagination: new SwiperPagination(
alignment: Alignment.centerRight,
builder: SwiperPagination.fraction),
))
],
));
}
}
class ExampleCustomPagination extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Custom Pagination"),
),
body: new Column(
children: <Widget>[
new Expanded(
child: new Swiper(
itemBuilder: (BuildContext context, int index) {
return new Image.asset(
images[index],
fit: BoxFit.fill,
);
},
autoplay: true,
itemCount: images.length,
reverse: false,
pagination: new SwiperPagination(
margin: new EdgeInsets.all(0.0),
builder: new SwiperCustomPagination(builder:
(BuildContext context, SwiperPluginConfig config) {
return new ConstrainedBox(
child: new Container(
color: Colors.white,
child: new Text(
"${titles[config.activeIndex]} ${config.activeIndex+1}/${config.itemCount}",
style: new TextStyle(fontSize: 20.0),
)),
constraints: new BoxConstraints.expand(height: 50.0),
);
})),
control: new SwiperControl(),
),
),
new Expanded(
child: new Swiper(
itemBuilder: (BuildContext context, int index) {
return new Image.asset(
images[index],
fit: BoxFit.fill,
);
},
autoplay: true,
itemCount: images.length,
reverse: false,
pagination: new SwiperPagination(
margin: new EdgeInsets.all(0.0),
builder: new SwiperCustomPagination(builder:
(BuildContext context, SwiperPluginConfig config) {
return new ConstrainedBox(
child: new Row(
children: <Widget>[
new Text(
"${titles[config.activeIndex]} ${config.activeIndex+1}/${config.itemCount}",
style: TextStyle(fontSize: 20.0),
),
new Expanded(
child: new Align(
alignment: Alignment.centerRight,
child: new DotSwiperPaginationBuilder(
color: Colors.black12,
activeColor: Colors.black,
size: 10.0,
activeSize: 20.0)
.build(context, config),
),
)
],
),
constraints: new BoxConstraints.expand(height: 50.0),
);
})),
control: new SwiperControl(color: Colors.redAccent),
),
)
],
));
}
}
class ExamplePhone extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Phone"),
),
body: new Stack(
children: <Widget>[
ConstrainedBox(
constraints: new BoxConstraints.expand(),
child: new Image.asset(
"images/bg.jpeg",
fit: BoxFit.fill,
),
),
new Swiper.children(
autoplay: false,
pagination: new SwiperPagination(
margin: new EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 30.0),
builder: new DotSwiperPaginationBuilder(
color: Colors.white30,
activeColor: Colors.white,
size: 20.0,
activeSize: 20.0)),
children: <Widget>[
new Image.asset(
"images/1.png",
fit: BoxFit.contain,
),
new Image.asset(
"images/2.png",
fit: BoxFit.contain,
),
new Image.asset("images/3.png", fit: BoxFit.contain)
],
)
],
),
);
}
}
class ScaffoldWidget extends StatelessWidget {
final Widget child;
final String title;
final List<Widget> actions;
ScaffoldWidget({this.child, this.title, this.actions});
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(title),
actions: actions,
),
body: child,
);
}
}