Challenge - 5 Problems
AnimationController Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate1:30remaining
What happens when AnimationController.repeat() is called?
Consider an AnimationController with duration 2 seconds. What is the visible behavior when calling
controller.repeat() in a Flutter app?Flutter
final controller = AnimationController(vsync: this, duration: Duration(seconds: 2)); controller.repeat();
Attempts:
2 left
💡 Hint
Think about what repeat() means for an animation's progress.
✗ Incorrect
The repeat() method makes the animation run forward continuously from 0.0 to 1.0 and then restarts at 0.0 automatically.
❓ lifecycle
intermediate1:30remaining
What happens if you don't dispose AnimationController?
In a StatefulWidget, what is the consequence of not calling
controller.dispose() on an AnimationController in the dispose() method?Flutter
class MyWidgetState extends State<MyWidget> with SingleTickerProviderStateMixin { late AnimationController controller; @override void initState() { super.initState(); controller = AnimationController(vsync: this, duration: Duration(seconds: 1)); } @override void dispose() { // Missing controller.dispose(); super.dispose(); } }
Attempts:
2 left
💡 Hint
Think about resources held by the controller and how Flutter manages them.
✗ Incorrect
AnimationController holds resources like ticker. Not disposing it causes memory leaks and performance degradation.
📝 Syntax
advanced1:30remaining
Which code snippet correctly creates an AnimationController with vsync?
Choose the code snippet that correctly initializes an AnimationController inside a State class with SingleTickerProviderStateMixin.
Attempts:
2 left
💡 Hint
Check the named parameters order and syntax.
✗ Incorrect
AnimationController requires named parameters. The correct order is vsync and duration, both named. The order of named parameters does not matter.
advanced
2:00remaining
How to synchronize AnimationController with page navigation?
You want an animation to start when a new page appears and reverse when leaving. Which lifecycle method is best to start the AnimationController forward animation?
Attempts:
2 left
💡 Hint
Think about how to detect page navigation events in Flutter.
✗ Incorrect
Using RouteObserver lets you detect when a page is pushed or popped to start or reverse animations accordingly.
🧠 Conceptual
expert2:00remaining
What is the value of AnimationController.value after calling reverse() from 0.0?
If an AnimationController's current value is 0.0 and you call
controller.reverse(), what will be the value of controller.value immediately after the call?Flutter
final controller = AnimationController(vsync: this, duration: Duration(seconds: 1)); controller.value = 0.0; controller.reverse(); final val = controller.value;
Attempts:
2 left
💡 Hint
Think about what reverse() does if the animation is already at the beginning.
✗ Incorrect
If the animation is at 0.0, calling reverse() does not move it backward; it stays at 0.0.