-
Notifications
You must be signed in to change notification settings - Fork 10
/
aircon_summer_refresher.dart
143 lines (124 loc) · 3.5 KB
/
aircon_summer_refresher.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
import 'package:flutter/material.dart' hide RefreshIndicator, RefreshIndicatorState;
import 'package:flutter/widgets.dart';
import 'package:flutter_gifimage/flutter_gifimage.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
class AirconSummerHeader extends RefreshIndicator {
AirconSummerHeader() : super(height: recommendedHeight, refreshStyle: RefreshStyle.Follow);
static double recommendedHeight = 80;
@override
State<StatefulWidget> createState() {
return AirconSummerHeaderState();
}
}
class AirconSummerHeaderState extends RefreshIndicatorState with SingleTickerProviderStateMixin {
var imagePath = './resources/refresher/aircon_summer/loading-fan.gif';
GifController _gifController;
@override
void initState() {
_gifController = GifController(
vsync: this,
value: 0,
);
super.initState();
}
@override
void onModeChange(RefreshStatus mode) {
if (mode == RefreshStatus.canRefresh || (mode == RefreshStatus.refreshing && _gifController.isAnimating == false)) {
_gifController.repeat(
min: 0,
max: 3.0,
period: Duration(milliseconds: (1000).floor()),
);
}
super.onModeChange(mode);
}
@override
Future<void> endRefresh() {
return super.endRefresh();
}
@override
void resetValue() {
_gifController.reset();
super.resetValue();
}
@override
Widget buildContent(BuildContext context, RefreshStatus mode) {
return GifImage(
image: AssetImage(
imagePath,
),
controller: _gifController,
height: 80.0,
);
}
@override
void dispose() {
_gifController.dispose();
super.dispose();
}
}
class AirconSummerFooter extends LoadIndicator {
final VoidCallback onClick;
AirconSummerFooter({this.onClick})
: super(onClick: onClick, loadStyle: LoadStyle.ShowWhenLoading, height: recommendedHeight);
static double recommendedHeight = 80;
@override
State<StatefulWidget> createState() {
return _AirconSummerFooterState();
}
}
class _AirconSummerFooterState extends LoadIndicatorState<AirconSummerFooter> with SingleTickerProviderStateMixin {
GifController _gifController;
bool started;
@override
void initState() {
started = false;
_gifController = GifController(
vsync: this,
value: 0,
);
super.initState();
}
@override
void dispose() {
_gifController.dispose();
super.dispose();
}
@override
void onModeChange(LoadStatus mode) {
if (mode == LoadStatus.idle && started) {
started = false;
_gifController.value = 0;
} else if (mode == LoadStatus.loading && !started) {
started = true;
if (!_gifController.isAnimating) {
_gifController.repeat(min: 0, max: 4, period: Duration(milliseconds: (1000).floor()));
}
} else if (mode == LoadStatus.canLoading) {
started = true;
if (!_gifController.isAnimating) {
_gifController.repeat(min: 0, max: 4, period: Duration(milliseconds: (1000).floor()));
}
}
super.onModeChange(mode);
}
@override
Future endLoading() {
if (_gifController.isAnimating) {
started = false;
_gifController.reset();
}
return super.endLoading();
}
@override
Widget buildContent(BuildContext context, LoadStatus mode) {
var imagePath = './resources/refresher/aircon_summer/fan-footer.gif';
return !started
? Container()
: GifImage(
image: AssetImage(imagePath),
controller: _gifController,
height: 80.0,
);
}
}