forked from peng8350/flutter_pulltorefresh
/
gif_indicator_example1.dart
185 lines (168 loc) · 4.59 KB
/
gif_indicator_example1.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
/*
* Author: Jpeng
* Email: peng8350@gmail.com
* Time: 2019-07-26 18:22
*/
import 'package:flutter/widgets.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:flutter_gifimage/flutter_gifimage.dart';
import 'package:flutter/material.dart'
hide RefreshIndicator, RefreshIndicatorState;
/*
I use my plugin to implements gif effect,this plugin can help you to controll gif easily,
see page to find about usage: (https://github.com/peng8350/flutter_gifimage)
*/
class GifHeader1 extends RefreshIndicator {
GifHeader1() : super(height: 80.0, refreshStyle: RefreshStyle.Follow);
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return GifHeader1State();
}
}
class GifHeader1State extends RefreshIndicatorState<GifHeader1>
with SingleTickerProviderStateMixin {
GifController _gifController;
@override
void initState() {
// TODO: implement initState
// init frame is 2
_gifController = GifController(
vsync: this,
value: 1,
);
super.initState();
}
@override
void onModeChange(RefreshStatus mode) {
// TODO: implement onModeChange
if (mode == RefreshStatus.refreshing) {
_gifController.repeat(
min: 0, max: 29, period: Duration(milliseconds: 500));
}
super.onModeChange(mode);
}
@override
Future<void> endRefresh() {
// TODO: implement endRefresh
_gifController.value = 30;
return _gifController.animateTo(59, duration: Duration(milliseconds: 500));
}
@override
void resetValue() {
// TODO: implement resetValue
// reset not ok , the plugin need to update lowwer
_gifController.value = 0;
super.resetValue();
}
@override
Widget buildContent(BuildContext context, RefreshStatus mode) {
// TODO: implement buildContent
return GifImage(
image: AssetImage("images/gifindicator1.gif"),
controller: _gifController,
height: 80.0,
width: 537.0,
);
}
@override
void dispose() {
// TODO: implement dispose
_gifController.dispose();
super.dispose();
}
}
class GifFooter1 extends StatefulWidget {
GifFooter1() : super();
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _GifFooter1State();
}
}
class _GifFooter1State extends State<GifFooter1>
with SingleTickerProviderStateMixin {
GifController _gifController;
@override
void initState() {
// TODO: implement initState
// init frame is 2
_gifController = GifController(
vsync: this,
value: 1,
);
super.initState();
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return CustomFooter(
height: 80,
builder: (context, mode) {
return GifImage(
image: AssetImage("images/gifindicator1.gif"),
controller: _gifController,
height: 80.0,
width: 537.0,
);
},
loadStyle: LoadStyle.ShowWhenLoading,
onModeChange: (mode) {
if (mode == LoadStatus.loading) {
_gifController.repeat(
min: 0, max: 29, period: Duration(milliseconds: 500));
}
},
endLoading: () async {
_gifController.value = 30;
return _gifController.animateTo(59,
duration: Duration(milliseconds: 500));
},
);
}
@override
void dispose() {
// TODO: implement dispose
_gifController.dispose();
super.dispose();
}
}
class GifIndicatorExample1 extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return GifIndicatorExample1State();
}
}
class GifIndicatorExample1State extends State<GifIndicatorExample1> {
RefreshController _controller = RefreshController();
@override
Widget build(BuildContext context) {
// TODO: implement build
return RefreshConfiguration.copyAncestor(
context: context,
// two attrs enable footer implements the effect in header default
enableBallisticLoad: false,
footerTriggerDistance: -80,
child: SmartRefresher(
controller: _controller,
enablePullUp: true,
header: GifHeader1(),
footer: GifFooter1(),
onRefresh: () async {
await Future.delayed(Duration(milliseconds: 2000));
_controller.refreshCompleted();
},
onLoading: () async {
await Future.delayed(Duration(milliseconds: 2000));
_controller.loadFailed();
},
child: ListView.builder(
itemBuilder: (c, q) => Card(),
itemCount: 50,
itemExtent: 100.0,
),
),
);
}
}