forked from peng8350/flutter_pulltorefresh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunningHeader.dart
78 lines (69 loc) · 2 KB
/
RunningHeader.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
/*
* Author: Jpeng
* Email: [email protected]
* Time: 2019-05-26 23:09
*/
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:flutter/material.dart'
hide RefreshIndicator, RefreshIndicatorState;
class RunningHeader extends RefreshIndicator {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return RunningHeaderState();
}
}
class RunningHeaderState extends RefreshIndicatorState<RunningHeader>
with TickerProviderStateMixin {
AnimationController _scaleAnimation;
AnimationController _offsetController;
Tween<Offset> offsetTween;
@override
void initState() {
// TODO: implement initState
_scaleAnimation = AnimationController(vsync: this);
_offsetController = AnimationController(
vsync: this, duration: Duration(milliseconds: 1000));
offsetTween = Tween(end: Offset(0.6, 0.0), begin: Offset(0.0, 0.0));
super.initState();
}
@override
void onOffsetChange(double offset) {
// TODO: implement onOffsetChange
if (!floating) {
_scaleAnimation.value = offset / 80.0;
}
super.onOffsetChange(offset);
}
@override
void resetValue() {
// TODO: implement handleModeChange
_scaleAnimation.value = 0.0;
_offsetController.value = 0.0;
}
@override
void dispose() {
// TODO: implement dispose
_scaleAnimation.dispose();
_offsetController.dispose();
super.dispose();
}
@override
Future<void> endRefresh() {
// TODO: implement endRefresh
return _offsetController.animateTo(1.0).whenComplete(() {});
}
@override
Widget buildContent(BuildContext context, RefreshStatus mode) {
// TODO: implement buildContent
return SlideTransition(
child: ScaleTransition(
child: (mode != RefreshStatus.idle || mode != RefreshStatus.canRefresh)
? Image.asset("images/custom_2.gif")
: Image.asset("images/custom_1.jpg"),
scale: _scaleAnimation,
),
position: offsetTween.animate(_offsetController),
);
}
}