Phase 4 · Interface EngineeringModule 28~52 min read

Animations & Motion

Use implicit and explicit animation, transitions, heroes, sequences, and gestures to communicate change without harming accessibility.

What you'll learn

Use implicit and explicit animation, transitions, heroes, sequences, and gestures to communicate change without harming accessibility. The lesson turns the APIs into a repeatable engineering workflow instead of a collection of isolated snippets.

By the end of this lesson, you'll be able to:

  • Apply Implicit animation in a production-shaped Flutter feature
  • Apply Controllers and tweens in a production-shaped Flutter feature
  • Apply Transitions in a production-shaped Flutter feature
  • Apply Hero in a production-shaped Flutter feature

Core mental model

Connect each API to the decision it supports. Flutter code stays maintainable when state, ownership, lifecycle, and platform boundaries are explicit.

ConceptWhat it meansDecision rule
Implicit animationA widget animates automatically between changed property valuesUse for simple local transitions with one target state
AnimationControllerAn owned timeline for explicit coordinationDispose it and use only when timing or direction needs control
Reduced motionA user preference to minimize nonessential movementRemove large spatial motion while preserving state feedback

Professional workflow

Work in small vertical slices and keep behavior observable from the first iteration.

  1. Define the accessible state transition boundary: user goal, inputs, visible states, ownership, and expected failures.
  2. Build the smallest working vertical slice with typed data and explicit dependencies.
  3. Represent loading, empty, success, and failure behavior where the feature can encounter them.
  4. Verify logic away from the UI, then exercise the rendered behavior at its public boundary.
  5. Inspect lifecycle, accessibility, performance, security, and platform behavior before widening the feature.
  6. Refactor only after behavior is protected by repeatable evidence.

Protect the frame

Keep build methods predictable, move side effects to explicit owners, and measure before introducing caches, isolates, or architectural layers.

Guided Flutter lab

Build a focused accessible state transition slice

This compact example keeps the important ownership and data-flow decisions visible so the behavior is easy to extend and test.

lib/completion_badge.dart
class CompletionBadge extends StatelessWidget {
  const CompletionBadge({super.key, required this.complete});
  final bool complete;

  @override
  Widget build(BuildContext context) {
    final reduceMotion = MediaQuery.disableAnimationsOf(context);
    return AnimatedContainer(
      duration: reduceMotion ? Duration.zero : const Duration(milliseconds: 220),
      curve: Curves.easeOut,
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
      decoration: BoxDecoration(
        color: complete ? Colors.green.shade700 : Colors.grey.shade700,
        borderRadius: BorderRadius.circular(999),
      ),
      child: Text(complete ? 'Complete' : 'In progress'),
    );
  }
}

Production practice

Contract

Define the accessible state transition inputs, outputs, owner, lifecycle, visible states, and platform assumptions before selecting APIs or packages.

Verification

Protect pure rules with unit tests and the rendered public contract with widget or integration evidence; include one unavailable or failure case.

Operations

Keep dependencies replaceable, log actionable context without user secrets, and measure user-visible behavior before optimizing.

Common failure mode

Long, decorative, or uninterruptible motion can delay tasks, trigger discomfort, and make rapid state changes visually misleading.

Independent workshop

Extend the guided lab into a review-ready accessible state transition feature that fits the running course portfolio app.

Your finished workshop must include:

  • Implicit animation
  • Controllers and tweens
  • Transitions
  • Hero
  • Staggered motion
  • Automated verification and a short design note

Definition of done

Demonstrate the happy path, an empty or unavailable state, and at least one failure path. Add an automated check and a short note explaining one design decision.

Recap & quick check

Key takeaways

  • Implicit animation: Use for simple local transitions with one target state
  • AnimationController: Dispose it and use only when timing or direction needs control
  • Reduced motion: Remove large spatial motion while preserving state feedback

Quick check

1. Which rule best applies to Implicit animation?

2. Which rule best applies to AnimationController?

3. Which rule best applies to Reduced motion?

Next: Custom Painting & Advanced Graphics