-
Notifications
You must be signed in to change notification settings - Fork 34
/
staggered_animation_replication.dart
executable file
·128 lines (118 loc) · 4 KB
/
staggered_animation_replication.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
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_sequence_animation/flutter_sequence_animation.dart';
class StaggeredAnimationReplication extends StatefulWidget {
@override
_StaggeredAnimationReplicationState createState() => new _StaggeredAnimationReplicationState();
}
class _StaggeredAnimationReplicationState extends State<StaggeredAnimationReplication> with SingleTickerProviderStateMixin{
late AnimationController controller;
late SequenceAnimation sequenceAnimation;
@override
void initState() {
super.initState();
controller = new AnimationController(vsync: this);
sequenceAnimation = new SequenceAnimationBuilder()
.addAnimatable(
animatable: new Tween<double>(begin: 0.0, end: 1.0),
from: Duration.zero,
to: const Duration(milliseconds: 200),
curve: Curves.ease,
tag: "opacity"
).addAnimatable(
animatable: new Tween<double>(begin: 50.0, end: 150.0),
from: const Duration(milliseconds: 250),
to: const Duration(milliseconds: 500),
curve: Curves.ease,
tag: "width"
).addAnimatable(
animatable: new Tween<double>(begin: 50.0, end: 150.0),
from: const Duration(milliseconds: 500),
to: const Duration(milliseconds: 750),
curve: Curves.ease,
tag: "height"
).addAnimatable(
animatable: new EdgeInsetsTween(begin: const EdgeInsets.only(bottom: 16.0), end: const EdgeInsets.only(bottom: 75.0),),
from: const Duration(milliseconds: 500),
to: const Duration(milliseconds: 750),
curve: Curves.ease,
tag: "padding"
).addAnimatable(
animatable: new BorderRadiusTween(begin: new BorderRadius.circular(4.0), end: new BorderRadius.circular(75.0),),
from: const Duration(milliseconds: 750),
to: const Duration(milliseconds: 1000),
curve: Curves.ease,
tag: "borderRadius"
).addAnimatable(
animatable: new ColorTween(begin: Colors.indigo[100], end: Colors.orange[400],),
from: const Duration(milliseconds: 1000),
to: const Duration(milliseconds: 1500),
curve: Curves.ease,
tag: "color"
).animate(controller);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
Widget _buildAnimation(BuildContext context, Widget? child) {
return new Container(
padding: sequenceAnimation["padding"].value,
alignment: Alignment.bottomCenter,
child: new Opacity(
opacity: sequenceAnimation["opacity"].value,
child: new Container(
width: sequenceAnimation["width"].value,
height: sequenceAnimation["height"].value,
decoration: new BoxDecoration(
color: sequenceAnimation["color"].value,
border: new Border.all(
color: Colors.indigo[300]!,
width: 3.0,
),
borderRadius: sequenceAnimation["borderRadius"].value,
),
),
),
);
}
Future<Null> _playAnimation() async {
try {
await controller.forward().orCancel;
await controller.reverse().orCancel;
} on TickerCanceled {
// the animation got canceled, probably because we were disposed
}
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Staggered Animation"),
),
body: new GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
_playAnimation();
},
child: new Center(
child: new Container(
width: 300.0,
height: 300.0,
decoration: new BoxDecoration(
color: Colors.black.withOpacity(0.1),
border: new Border.all(
color: Colors.black.withOpacity(0.5),
),
),
child: new AnimatedBuilder(
animation: controller,
builder: _buildAnimation
),
),
),
),
);
}
}