Fireship · @fireship
Flutter Animation - Radial Menu at 60FPS
Uploaded February 25, 2019 · Length 9:58
Summary
Building a radial menu in Flutter with animations at 60FPS, using trigonometry and vector math.
- flutter animation
- radial menu
- 60fps
- trigonometry
- vector math
- dart programming
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
[Music]
- 0:06
building a butter smooth UI is extremely
- 0:09
important in the world of native apps
- 0:10
it only takes a small amount of jank for
- 0:12
people to think your app sucks that's
- 0:13
why one of my favorite things about
- 0:14
flutter is how beautifully it renders
- 0:16
the animations we can use the built-in
- 0:17
profiler to see that we easily achieve
- 0:19
60 frames per second even for this
- 0:21
complex rotating radio menu in today's
- 0:24
video you'll learn all about flutter
- 0:25
animations by building this menu from
- 0:26
scratch if you're new here like and
- 0:28
subscribe and you can find the full
- 0:29
source code on fire ship IL before we
- 0:32
get started I have a confession to make
- 0:33
in college I failed trigonometry I
- 0:35
vividly remember scoring zero out of 100
- 0:38
points on the midterm and I probably
- 0:39
didn't even take the final and that's
- 0:40
not good because we need to use
- 0:41
trigonometry in this video to determine
- 0:43
where to place the different elements on
- 0:45
the menu if we take a closer look at
- 0:47
this menu we actually have ten different
- 0:48
buttons stacked on top of each other
- 0:50
the open and close buttons stay in the
- 0:51
middle and then they scale up and down
- 0:53
depending on whether or not the menu is
- 0:55
opened or closed when opened all of the
- 0:57
outer buttons will be translated or
- 0:59
moved to a specific bearing from the
- 1:01
center point this is where trig comes
- 1:02
into play because we need to calculate a
- 1:04
specific XY coordinate based on an angle
- 1:06
from the center but don't worry too much
- 1:08
about that it's actually a very easy
- 1:09
calculation and this entire demo only
- 1:11
takes about 150 lines of code which is
- 1:13
pretty crazy and as a final touch will
- 1:15
also add a rotation to the entire stack
- 1:17
of buttons so that way it rotates
- 1:19
clockwise when opening and
- 1:20
counterclockwise when closing to get
- 1:23
started you'll need to have a flutter
- 1:24
app and then I also have vector math
- 1:25
installed and optionally fun awesome for
- 1:28
some better icons the material then if
- 1:30
we go into our main dart file you can
- 1:32
see that I'm importing dart math and
- 1:34
then I'm importing radians from vector
- 1:36
math and it's important to do the import
- 1:37
like this because it has some
- 1:38
conflicting classes with flutter now
- 1:41
we'll go down here to our material app
- 1:42
and we'll just add a scaffold and for
- 1:44
this demo we'll just have the menu fill
- 1:46
up the entire screen and for that we can
- 1:47
use a sized box and have it expand to
- 1:50
fill out the entire viewport and then
- 1:51
the child for that box will be our
- 1:53
custom radial menu widget when working
- 1:56
with animations the first thing you
- 1:57
usually start with is a stateful widget
- 1:59
the only thing this widget is concerned


