-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJcyAnimateSlide.dart
71 lines (60 loc) · 1.72 KB
/
JcyAnimateSlide.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
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class JcyAnimateSlide extends StatefulWidget {
final Widget child;
final bool active; // 是否显示
final int duration; // 动画时间(毫秒)
final Curve curve; // 动画效果
final String type; // 动画类型
JcyAnimateSlide({
@required this.child,
@required this.active,
this.type = 'scale',
this.duration = 700,
this.curve = Curves.easeOut
});
@override
_JcyAnimateSlide createState () => new _JcyAnimateSlide();
}
class _JcyAnimateSlide extends State<JcyAnimateSlide> with SingleTickerProviderStateMixin{
AnimationController controller;
Animation<Offset> animation;
Animation curve;
@override
void didUpdateWidget (oldWidget) {
super.didUpdateWidget(oldWidget);
if(widget.active) {
controller.forward();
} else {
controller.reverse();
}
}
@override
void initState () {
super.initState();
controller = AnimationController(
vsync: this,
duration: Duration(
milliseconds: widget.duration
)
);
//动画开始、结束、向前移动或向后移动时会调用StatusListener
// controller.addStatusListener((status) {
// if (status == AnimationStatus.completed) {
// controller.reverse();
// } else if (status == AnimationStatus.dismissed) {
// controller.forward();
// }
// });
curve =
new CurvedAnimation(parent: controller, curve: widget.curve);
animation = Tween(begin: Offset(0, 1), end: Offset(0, 0)).animate(curve);
}
@override
Widget build (BuildContext context) {
return SlideTransition(
position: animation,
child: widget.child,
);
}
}