This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.dart
103 lines (94 loc) · 3.47 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
import 'package:flutter/material.dart';
import 'package:flutter_banner_widget/banner/banner_entity.dart';
import 'package:flutter_banner_widget/banner/banner_widget.dart';
void main() => runApp(MaterialApp(home: HomePage()));
class SimpleEntity extends Object with BannerEntity {
final String obj;
final String url;
final String title;
SimpleEntity({this.obj, this.url, this.title});
@override
get bannerUrl => url;
@override
get bannerTitle => title;
}
class HomePage extends StatelessWidget {
final GlobalKey<BannerState> globalKey = new GlobalKey<BannerState>();
final List<SimpleEntity> entity = [
new SimpleEntity(
url:
'http://p1.img.cctvpic.com/photoworkspace/2018/05/18/2018051814594647287.jpg',
title: '治愈系小可爱和你说晚安~',
obj:
'http://live.ipanda.com/2018/05/18/VIDEKRkGRBOtjr33LfKamvlM180518.shtml'),
new SimpleEntity(
url:
'http://p1.img.cctvpic.com/photoworkspace/2018/05/18/2018051814220084352.jpg',
title: '“太妃糖”:麻麻,我走啦!',
obj:
'http://live.ipanda.com/2018/05/18/VIDEhZDFWlTidfugBlZa8qDl180518.shtml'),
new SimpleEntity(
url:
'http://p1.img.cctvpic.com/photoworkspace/2018/05/18/2018051814245872100.jpg',
title: '冷静冷静,这也太有爱了吧~',
obj:
'http://live.ipanda.com/2018/05/18/VIDERxEzGP40e4zIsKvZO0no180518.shtml'),
new SimpleEntity(
url:
'http://p1.img.cctvpic.com/photoworkspace/2018/05/18/2018051814175817985.jpg',
title: '“福豹”:跟我一起嗨~',
obj:
'http://live.ipanda.com/2018/05/18/VIDEIUt6LWRTnP5rBSqjqZRe180518.shtml'),
];
final List<SimpleEntity> localEntity = [
new SimpleEntity(
url: 'lib/image/banner1.jpg', title: '本地资源第一张', obj: 'message'),
new SimpleEntity(
url: 'lib/image/banner2.jpg', title: '本地资源第二张', obj: 'message'),
new SimpleEntity(
url: 'lib/image/banner3.png', title: '本地资源第三张', obj: 'message'),
new SimpleEntity(
url: 'lib/image/banner4.jpg', title: '本地资源第四张', obj: 'message'),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter BannerWidget'),
),
body: Center(
child: Column(
children: <Widget>[
BannerWidget(
entity: entity,
key: globalKey,
delayTime: 500,
duration: 500,
),
Center(
child: MaterialButton(
color: Colors.black12,
padding: EdgeInsets.all(6.0),
onPressed: () => globalKey.currentState.start(),
child: Text('start'))),
Center(
child: MaterialButton(
color: Colors.black12,
padding: EdgeInsets.all(6.0),
onPressed: () => globalKey.currentState.stop(),
child: Text('stop'))),
new Padding(padding: EdgeInsets.all(6.0), child: Text('加载本地图片')),
BannerWidget(
build: (position, entity) {
return Image.asset(entity.bannerUrl, fit: BoxFit.cover);
},
entity: localEntity,
delayTime: 1000,
duration: 1000,
),
],
),
),
);
}
}