0
0
Fluttermobile~20 mins

AnimationController in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
AnimationController Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
1: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();
AThe animation does not start until controller.forward() is called.
BThe animation runs once forward from 0.0 to 1.0 and then stops.
CThe animation runs forward then backward repeatedly between 0.0 and 1.0.
DThe animation runs forward repeatedly from 0.0 to 1.0 without stopping.
Attempts:
2 left
💡 Hint
Think about what repeat() means for an animation's progress.
lifecycle
intermediate
1: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();
  }
}
AThe app will leak memory and may cause performance issues over time.
BThe controller will automatically dispose itself when the widget is removed.
CThe animation will stop immediately without errors.
DThe app will crash with a runtime error.
Attempts:
2 left
💡 Hint
Think about resources held by the controller and how Flutter manages them.
📝 Syntax
advanced
1: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.
Acontroller = AnimationController(vsync: this, duration: Duration(seconds: 1));
Bcontroller = AnimationController(duration: Duration(seconds: 1), vsync: this);
Ccontroller = AnimationController(Duration(seconds: 1), this);
Dcontroller = AnimationController(this, duration: Duration(seconds: 1));
Attempts:
2 left
💡 Hint
Check the named parameters order and syntax.
navigation
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?
AStart animation in initState() and reverse in dispose().
BStart animation in didPush() of RouteObserver and reverse in didPop().
CStart animation in didChangeDependencies() and reverse in deactivate().
DStart animation in build() and reverse in didUpdateWidget().
Attempts:
2 left
💡 Hint
Think about how to detect page navigation events in Flutter.
🧠 Conceptual
expert
2: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;
AThrows an error because reverse() cannot be called at 0.0 value.
B1.0 because reverse() sets the animation to the end before reversing.
C0.0 because the animation is already at the start and cannot reverse further.
DA value between 0.0 and 1.0 depending on the animation progress.
Attempts:
2 left
💡 Hint
Think about what reverse() does if the animation is already at the beginning.