spread_widget.dart
1.47 KB
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
import 'package:flutter/material.dart';
class ScaleAnimatedContentSim extends StatefulWidget {
final Widget child;
final bool show;
const ScaleAnimatedContentSim({Key key, this.child, this.show = false})
: super(key: key);
@override
ScaleAnimatedContentSimState createState() => ScaleAnimatedContentSimState();
}
class ScaleAnimatedContentSimState extends State<ScaleAnimatedContentSim>
with TickerProviderStateMixin {
AnimationController animationController;
Animation<double> animation;
@override
void initState() {
animationController = new AnimationController(
vsync: this,
duration: new Duration(milliseconds: 600),
);
// animationSlideUp = new Tween(begin: 0.0,end: 1.0).animate(animationController);
animation = Tween(begin: 0.0, end: 1.0).animate(animationController);
if (widget.show) {
animationController.forward();
}
super.initState();
}
@override
void didUpdateWidget(ScaleAnimatedContentSim oldWidget) {
if (widget != oldWidget) {
if (widget.show && !oldWidget.show) {
animationController.forward(from: 0.0);
} else if (!widget.show) {
animationController.reverse();
}
}
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) {
return ScaleTransition(
scale: animation,
child: widget.child,
);
}
@override
void dispose() {
animationController.dispose();
super.dispose();
}
}