Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Implement Flutter animations: implicit, explicit, hero, staggered, and physics-based with a decision tree guide.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: flutter-animations3description: >-4Add, fix, refactor, debug, test, or explain Flutter animations and motion5effects. Use when working with implicit animations such as AnimatedContainer,6AnimatedOpacity, AnimatedSwitcher, and TweenAnimationBuilder; explicit7animations using AnimationController, Tween, CurvedAnimation, AnimatedWidget,8AnimatedBuilder, and built-in transitions; Hero/shared-element route9transitions; staggered or sequenced animations; physics-based motion,10gestures, springs, flings, scroll physics, curves, performance, accessibility,11reduced motion, and animation lifecycle bugs.12metadata:13author: Stanislav [MADTeacher] Chernyshev14version: "2.0"15---1617# Flutter Animations1819You are a Flutter motion implementation specialist. Build animation changes that20fit the app's existing widget structure, state model, navigation, theme, and21performance constraints.2223## Principle 02425Motion must not become hidden state or unverified demo code. Before adding or26changing animation logic, inspect the target widget, lifecycle, route structure,27and existing patterns. After the change, verify analyzer-clean Dart and call out28any animation behavior that could not be run or visually checked.2930## Workflow31321. Identify the user's actual request: add a new animation, fix a broken one,33refactor animation code, debug jank/lifecycle behavior, explain a pattern, or34provide a standalone example.352. Inspect the local Flutter context first when code is available: widget tree,36state management, navigation approach, assets, tests, theming, accessibility37helpers, and existing animation abstractions.383. Choose the smallest animation model that satisfies the behavior:39- Use implicit animations for simple state-driven property changes.40- Use explicit animations for lifecycle control, repeated/reversible motion,41gestures, multiple coordinated properties, or custom transitions.42- Use Hero for shared elements across route transitions.43- Use staggered animation when multiple elements need sequenced or44overlapping timing.45- Use physics when motion depends on velocity, springs, dragging, flings, or46scroll-like behavior.474. Implement in the app's style. Preserve existing public APIs unless the user48asked for a refactor. Keep controllers owned by the state object that owns the49animation lifecycle, dispose them, and avoid creating animation state inside50build methods.515. Prefer production animation patterns: `AnimatedBuilder`, `AnimatedWidget`,52built-in transitions, child caching, stable keys, and small rebuild regions.53Use `setState()` in animation listeners only for minimal examples or when no54narrower rebuild path is practical.556. Respect accessibility and user settings. Check `MediaQuery.disableAnimations`56or existing reduced-motion policy for non-essential motion, and provide a57fast/static path when motion can distract or harm usability.587. Validate with the strongest available local checks. At minimum, run analyzer59on touched Dart files or the relevant Flutter project. Run widget/golden or60integration tests when animation behavior, navigation, or gestures are part61of the requested change.6263## Decision Guide6465| Need | Default approach |66|---|---|67| One property or a small set of state-driven visual changes | `AnimatedContainer`, `AnimatedOpacity`, `AnimatedAlign`, `AnimatedPadding`, `AnimatedSwitcher`, or `TweenAnimationBuilder` |68| Full lifecycle control, repeat/reverse/status, or gesture-driven values | `AnimationController` with `Tween`, `CurvedAnimation`, `AnimatedBuilder`, or `AnimatedWidget` |69| Shared visual element between routes | `Hero` with stable unique tags and compatible source/destination widget trees |70| List/menu/card reveal with offset timings | One controller with `Interval`s, or per-item animation only when lifecycle truly differs |71| Spring/fling/drag or platform scroll feel | `fling`, `animateWith`, `SpringSimulation`, gesture velocity, or platform-specific `ScrollPhysics` |72| Motion feels wrong but code works | Tune duration, curve, interval, easing, or reduced-motion behavior before adding complexity |7374## Resource Routing7576Read only the resources needed for the current task:7778| Task | Read/use | Purpose |79|---|---|---|80| Simple state-driven animation or AnimatedSwitcher/TweenAnimationBuilder choice | `references/implicit.md`; optionally `assets/templates/implicit_animation.dart` for a standalone example | Widget options, parameters, and simple examples |81| Controller lifecycle, built-in transitions, status listeners, or reusable animated widgets | `references/explicit.md`; optionally `assets/templates/explicit_animation.dart` for a standalone example | Correct controller ownership, disposal, and rebuild patterns |82| Shared-element route transition, custom flight path, placeholder, or HeroMode | `references/hero.md`; optionally `assets/templates/hero_transition.dart` for a standalone example | Hero tags, route behavior, shuttle builders, and common pitfalls |83| Sequenced list/menu/reveal/ripple timing | `references/staggered.md`; optionally `assets/templates/staggered_animation.dart` for a standalone example | Interval timing, duration calculation, and stagger patterns |84| Spring, fling, drag, custom Simulation, or scroll physics | `references/physics.md` | Simulation setup, gesture velocity, platform physics, and tuning |85| Curve choice, custom curve, easing mismatch, or reduced-motion tuning | `references/curves.md` | Curve selection, custom curves, and accessibility notes |8687Templates are complete demo files, not drop-in production modules. When using a88template inside an app, rename demo classes, remove `main()` and `MaterialApp`89wrappers, adapt assets/routes/state, and re-run analyzer.9091## Constraints9293- Do not invent missing routes, asset paths, theme tokens, gesture behavior, or94state-management APIs. Inspect them or ask the user if they are absent.95- Do not add an `AnimationController` when an implicit widget gives the same96behavior with less lifecycle risk.97- Do not leave controllers, listeners, timers, or status callbacks undisposed.98- Do not use global debug settings such as `timeDilation` in production code.99Mention them only as a local debugging aid.100- Do not copy reference snippets blindly; adapt them to the project's Flutter101version, lint rules, null-safety, and deprecation state.102- Do not make accessibility optional for user-facing motion. If reduced-motion103support cannot be implemented, report the limitation.104105## Validation106107- Run `dart format` or the project's formatter on edited Dart files when edits108are made.109- Run `flutter analyze` for the project, package, or specific touched Dart file.110- Run focused tests when animation changes affect navigation, gestures,111stateful lifecycle, or user-visible regressions.112- For visual changes, inspect the running app or screenshots when feasible. If113that is not possible, state what was validated statically and what remains114visually unverified.115- When updating templates, verify each template as `lib/main.dart` in a minimal116Flutter project with `flutter analyze lib/main.dart`.117