/
hello_waves.dart
172 lines (160 loc) · 4.44 KB
/
hello_waves.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:footage/footage.dart';
class HelloWavesScene extends StatelessWidget {
const HelloWavesScene({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Markers(
markers: const [
Marker(Time.frames(0), 'Intro'),
Marker(Time.frames(10), 'Title'),
Marker(Time.frames(60), 'Outro', color: Colors.pink),
],
child: Stack(
children: [
const Loop(
duration: Time.frames(20),
child: Sequence(
name: 'Repeated circles',
from: Time.frames(0),
duration: Time.frames(10),
child: GrowingCircle(
maxScale: 3,
),
),
),
Sequence(
name: 'Circles',
from: const Time.frames(20),
duration: const Time.frames(40),
child: Stack(
children: const [
Sequence(
name: 'Circle 1',
from: Time.frames(0),
duration: Time.frames(20),
child: GrowingCircle(
maxScale: 5,
),
),
Sequence(
name: 'Circle 2',
from: Time.frames(10),
duration: Time.frames(30),
child: GrowingCircle(
maxScale: 10,
),
),
Sequence(
name: 'Circle 3',
from: Time.frames(20),
duration: Time.frames(20),
child: GrowingCircle(
maxScale: 30,
),
),
],
),
),
const Sequence(
name: 'Hello',
from: Time.frames(10),
duration: Time.frames(30),
child: RotatingTitle(
fontSize: 42,
title: 'Hello',
startAngle: 0,
endAngle: math.pi,
),
),
const Sequence(
name: 'World',
from: Time.frames(25),
duration: Time.frames(30),
child: RotatingTitle(
fontSize: 82,
title: 'World',
startAngle: math.pi,
endAngle: math.pi * 2,
),
),
],
),
);
}
}
class GrowingCircle extends StatelessWidget {
const GrowingCircle({
Key? key,
this.maxScale = 10,
this.child = const SizedBox(),
}) : super(key: key);
final double maxScale;
final Widget child;
static final colors = TweenSequence([
TweenSequenceItem(
tween: ColorTween(begin: Colors.pink.withAlpha(0), end: Colors.red),
weight: 2,
),
TweenSequenceItem(
tween: ColorTween(begin: Colors.red, end: Colors.blue.withAlpha(0)),
weight: 2,
),
]);
@override
Widget build(BuildContext context) {
final time = context.video.time();
return Center(
child: Transform.scale(
scale: Curves.easeOutQuart.transform(time) * maxScale,
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: colors.transform(Curves.easeOutQuart.transform(time))!,
shape: BoxShape.circle,
),
child: child,
),
),
);
}
}
class RotatingTitle extends StatelessWidget {
const RotatingTitle({
Key? key,
required this.startAngle,
required this.endAngle,
required this.fontSize,
required this.title,
}) : super(key: key);
final double startAngle;
final double endAngle;
final String title;
final double fontSize;
static final opacity = TweenSequence([
TweenSequenceItem(tween: Tween(begin: 0.0, end: 1.0), weight: 2),
TweenSequenceItem(tween: Tween(begin: 1.0, end: 0.0), weight: 1),
]);
@override
Widget build(BuildContext context) {
final time = context.video.time();
return Opacity(
opacity: opacity.transform(Curves.easeInOut.transform(time)),
child: Center(
child: Transform.rotate(
angle: startAngle +
(endAngle - startAngle) * Curves.easeInOut.transform(time),
child: Text(
title,
style: TextStyle(
fontFamily: 'Roboto',
fontSize: fontSize,
),
),
),
),
);
}
}