How to reduce AnimationController boilerplate code: Flutter Hooks vs extending the State class

  Рет қаралды 2,546

Andrea Bizzotto

Andrea Bizzotto

Күн бұрын

How to use Flutter Hooks or State subclassing to reduce your AnimationController boilerplate code.
Written tutorial: 👇👇
codewithandrea...
Join my FREE email course to become a Flutter expert with the best resources, at your own pace: codewithandrea...
Want to master animations in Flutter? Check out my full animations course: 👇👇
codewithandrea...
Happy coding!

Пікірлер: 5
@crazy-man
@crazy-man 3 жыл бұрын
yes cool, just wanted to get rid of these long constructs for creating animation
@theGoldyMan
@theGoldyMan 3 жыл бұрын
That's all cool if you have one Animation controller, what if you have several. This pattern becomes unusable.
@CodeWithAndrea
@CodeWithAndrea 3 жыл бұрын
How often does that happen? I have apps with many animation controllers, but all in separate widgets.
@theGoldyMan
@theGoldyMan 3 жыл бұрын
@@CodeWithAndrea as soon as you have 2 things to animate that have different timings. For example, I'm making an audio player that looks like magnetophon. I want the 2 reels to turn with a different speed and I want to update that speeds depending on the elapsed / remaining time. Or I have a button that on click have to scale down and up and at the same time to fire a water ripple like effect( not like inkwell, but the ripple is outside the button). Sometimes you can get away with Interval but not always, and that's when you need to add more controllers. I actually remember that when i was working on the flutter clock challenge, I had 3 controlers, one for hours, one for minutes and one for seconds. On second though I could move the animation controller for each reel indside another widget. But then the controlling of when to start when to stop, when to pause when to reverse with a certain speed (timing change) becomes very troublesome.
@CodeWithAndrea
@CodeWithAndrea 3 жыл бұрын
@@theGoldyMan Maybe I don't understand this fully, but I would still opt for creating separate widgets for parts of the UI that depend on a single AnimationController, and use a parent widget to control those widgets via GlobalKey. Or if you really need multiple controllers inside a single widgets, maybe do it with flutter_hooks? The state subclassing approach works for simplifying the boilerplate with a single AnimationController, which should be the majority of cases.
Flutter Animations Course Launch: Enroll Today - Early Access!
5:48
Andrea Bizzotto
Рет қаралды 5 М.
Flutter Hooks - Say Goodbye To Stateful Widget
10:06
Avalanche
Рет қаралды 56 М.
啊?就这么水灵灵的穿上了?
00:18
一航1
Рет қаралды 72 МЛН
Cool Parenting Gadget Against Mosquitos! 🦟👶 #gen
00:21
TheSoul Music Family
Рет қаралды 32 МЛН
How to build any kind of app in Flutter (and overcome Tutorial Hell)
9:42
Top 16 Dart Tips and Tricks Every Flutter Developer Should Know
11:44
Andrea Bizzotto
Рет қаралды 59 М.
What Everyone Ought to Know about Flutter Hooks!
10:17
Flutter Athletes
Рет қаралды 168
Vim Tips I Wish I Knew Earlier
23:00
Sebastian Daschner
Рет қаралды 72 М.
I reverse engineered Next to find what they are hiding
29:48
Theo - t3․gg
Рет қаралды 10 М.
Exploring Transform And Matrix4 In Flutter
6:59
Deven Joshi
Рет қаралды 19 М.
Flutter State Management Basics and Useful Resources
4:39
Andrea Bizzotto
Рет қаралды 12 М.
啊?就这么水灵灵的穿上了?
00:18
一航1
Рет қаралды 72 МЛН