Fireship · @fireship

Flutter Animation - Radial Menu at 60FPS

Uploaded February 25, 2019 · Length 9:58

Flutter Animation -  Radial Menu at 60FPS

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.

  1. 0:00

    [Music]

  2. 0:06

    building a butter smooth UI is extremely

  3. 0:09

    important in the world of native apps

  4. 0:10

    it only takes a small amount of jank for

  5. 0:12

    people to think your app sucks that's

  6. 0:13

    why one of my favorite things about

  7. 0:14

    flutter is how beautifully it renders

  8. 0:16

    the animations we can use the built-in

  9. 0:17

    profiler to see that we easily achieve

  10. 0:19

    60 frames per second even for this

  11. 0:21

    complex rotating radio menu in today's

  12. 0:24

    video you'll learn all about flutter

  13. 0:25

    animations by building this menu from

  14. 0:26

    scratch if you're new here like and

  15. 0:28

    subscribe and you can find the full

  16. 0:29

    source code on fire ship IL before we

  17. 0:32

    get started I have a confession to make

  18. 0:33

    in college I failed trigonometry I

  19. 0:35

    vividly remember scoring zero out of 100

  20. 0:38

    points on the midterm and I probably

  21. 0:39

    didn't even take the final and that's

  22. 0:40

    not good because we need to use

  23. 0:41

    trigonometry in this video to determine

  24. 0:43

    where to place the different elements on

  25. 0:45

    the menu if we take a closer look at

  26. 0:47

    this menu we actually have ten different

  27. 0:48

    buttons stacked on top of each other

  28. 0:50

    the open and close buttons stay in the

  29. 0:51

    middle and then they scale up and down

  30. 0:53

    depending on whether or not the menu is

  31. 0:55

    opened or closed when opened all of the

  32. 0:57

    outer buttons will be translated or

  33. 0:59

    moved to a specific bearing from the

  34. 1:01

    center point this is where trig comes

  35. 1:02

    into play because we need to calculate a

  36. 1:04

    specific XY coordinate based on an angle

  37. 1:06

    from the center but don't worry too much

  38. 1:08

    about that it's actually a very easy

  39. 1:09

    calculation and this entire demo only

  40. 1:11

    takes about 150 lines of code which is

  41. 1:13

    pretty crazy and as a final touch will

  42. 1:15

    also add a rotation to the entire stack

  43. 1:17

    of buttons so that way it rotates

  44. 1:19

    clockwise when opening and

  45. 1:20

    counterclockwise when closing to get

  46. 1:23

    started you'll need to have a flutter

  47. 1:24

    app and then I also have vector math

  48. 1:25

    installed and optionally fun awesome for

  49. 1:28

    some better icons the material then if

  50. 1:30

    we go into our main dart file you can

  51. 1:32

    see that I'm importing dart math and

  52. 1:34

    then I'm importing radians from vector

  53. 1:36

    math and it's important to do the import

  54. 1:37

    like this because it has some

  55. 1:38

    conflicting classes with flutter now

  56. 1:41

    we'll go down here to our material app

  57. 1:42

    and we'll just add a scaffold and for

  58. 1:44

    this demo we'll just have the menu fill

  59. 1:46

    up the entire screen and for that we can

  60. 1:47

    use a sized box and have it expand to

  61. 1:50

    fill out the entire viewport and then

  62. 1:51

    the child for that box will be our

  63. 1:53

    custom radial menu widget when working

  64. 1:56

    with animations the first thing you

  65. 1:57

    usually start with is a stateful widget

  66. 1:59

    the only thing this widget is concerned