Challenge - 5 Problems
Tween Animation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the output of this Tween animation code?
Consider this Flutter code snippet that animates a container's width from 100 to 200 pixels over 2 seconds. What will be the width of the container exactly at 1 second after the animation starts?
Flutter
AnimationController controller = AnimationController(duration: Duration(seconds: 2), vsync: this); Animation<double> animation = Tween<double>(begin: 100.0, end: 200.0).animate(controller); controller.forward(); // At 1 second, what is animation.value?
Attempts:
2 left
💡 Hint
Tween interpolates linearly between begin and end values over the animation duration.
✗ Incorrect
The Tween animates from 100 to 200 over 2 seconds. At 1 second (halfway), the value is halfway between 100 and 200, which is 150.
❓ lifecycle
intermediate1:30remaining
Which method should you override to dispose of a Tween animation controller properly?
In a StatefulWidget using a Tween animation with an AnimationController, which lifecycle method is the correct place to call controller.dispose() to avoid memory leaks?
Attempts:
2 left
💡 Hint
Dispose is for cleaning up resources when the widget is removed.
✗ Incorrect
The dispose() method is called when the widget is permanently removed. This is the right place to dispose of the AnimationController to free resources.
📝 Syntax
advanced2:00remaining
What error does this Tween animation code produce?
Examine this Flutter code snippet:
AnimationController controller = AnimationController(duration: Duration(seconds: 1));
Animation animation = Tween(begin: 0.0, end: 100.0).animate(controller);
What error will this code cause?
Flutter
AnimationController controller = AnimationController(duration: Duration(seconds: 1)); Animation<double> animation = Tween<double>(begin: 0.0, end: 100.0).animate(controller);
Attempts:
2 left
💡 Hint
AnimationController requires a vsync parameter to optimize resource usage.
✗ Incorrect
AnimationController requires a vsync parameter (usually a TickerProvider) to prevent offscreen animations from consuming resources. Omitting it causes a compile error.
advanced
1:30remaining
How to restart a Tween animation on button press?
You have a Tween animation controlled by AnimationController. Which code snippet correctly restarts the animation from the beginning when a button is pressed?
Attempts:
2 left
💡 Hint
Resetting sets animation back to start before playing forward.
✗ Incorrect
Calling reset() sets the animation to the beginning (value 0). Then forward() plays it from start. Just calling forward() continues from current position.
🧠 Conceptual
expert2:30remaining
What is the effect of using CurvedAnimation with Tween animations?
In Flutter, when you wrap a Tween animation with a CurvedAnimation using Curves.easeInOut, what is the visual effect on the animation?
Attempts:
2 left
💡 Hint
Curves modify the rate of change over time.
✗ Incorrect
CurvedAnimation applies a non-linear timing curve to the animation, making it start slowly, accelerate in the middle, and slow down at the end, creating a natural motion effect.