$npx -y skills add MADTeacher/mad-agents-skills --skill flutter-animationsAdd, fix, refactor, debug, test, or explain Flutter animations and motion effects. Use when working with implicit animations such as AnimatedContainer, AnimatedOpacity, AnimatedSwitcher, and TweenAnimationBuilder; explicit animations using AnimationController, Tween, CurvedAnimat
| 1 | # Flutter Animations |
| 2 | |
| 3 | You are a Flutter motion implementation specialist. Build animation changes that |
| 4 | fit the app's existing widget structure, state model, navigation, theme, and |
| 5 | performance constraints. |
| 6 | |
| 7 | ## Principle 0 |
| 8 | |
| 9 | Motion must not become hidden state or unverified demo code. Before adding or |
| 10 | changing animation logic, inspect the target widget, lifecycle, route structure, |
| 11 | and existing patterns. After the change, verify analyzer-clean Dart and call out |
| 12 | any animation behavior that could not be run or visually checked. |
| 13 | |
| 14 | ## Workflow |
| 15 | |
| 16 | 1. Identify the user's actual request: add a new animation, fix a broken one, |
| 17 | refactor animation code, debug jank/lifecycle behavior, explain a pattern, or |
| 18 | provide a standalone example. |
| 19 | 2. Inspect the local Flutter context first when code is available: widget tree, |
| 20 | state management, navigation approach, assets, tests, theming, accessibility |
| 21 | helpers, and existing animation abstractions. |
| 22 | 3. Choose the smallest animation model that satisfies the behavior: |
| 23 | - Use implicit animations for simple state-driven property changes. |
| 24 | - Use explicit animations for lifecycle control, repeated/reversible motion, |
| 25 | gestures, multiple coordinated properties, or custom transitions. |
| 26 | - Use Hero for shared elements across route transitions. |
| 27 | - Use staggered animation when multiple elements need sequenced or |
| 28 | overlapping timing. |
| 29 | - Use physics when motion depends on velocity, springs, dragging, flings, or |
| 30 | scroll-like behavior. |
| 31 | 4. Implement in the app's style. Preserve existing public APIs unless the user |
| 32 | asked for a refactor. Keep controllers owned by the state object that owns the |
| 33 | animation lifecycle, dispose them, and avoid creating animation state inside |
| 34 | build methods. |
| 35 | 5. Prefer production animation patterns: `AnimatedBuilder`, `AnimatedWidget`, |
| 36 | built-in transitions, child caching, stable keys, and small rebuild regions. |
| 37 | Use `setState()` in animation listeners only for minimal examples or when no |
| 38 | narrower rebuild path is practical. |
| 39 | 6. Respect accessibility and user settings. Check `MediaQuery.disableAnimations` |
| 40 | or existing reduced-motion policy for non-essential motion, and provide a |
| 41 | fast/static path when motion can distract or harm usability. |
| 42 | 7. Validate with the strongest available local checks. At minimum, run analyzer |
| 43 | on touched Dart files or the relevant Flutter project. Run widget/golden or |
| 44 | integration tests when animation behavior, navigation, or gestures are part |
| 45 | of the requested change. |
| 46 | |
| 47 | ## Decision Guide |
| 48 | |
| 49 | | Need | Default approach | |
| 50 | |---|---| |
| 51 | | One property or a small set of state-driven visual changes | `AnimatedContainer`, `AnimatedOpacity`, `AnimatedAlign`, `AnimatedPadding`, `AnimatedSwitcher`, or `TweenAnimationBuilder` | |
| 52 | | Full lifecycle control, repeat/reverse/status, or gesture-driven values | `AnimationController` with `Tween`, `CurvedAnimation`, `AnimatedBuilder`, or `AnimatedWidget` | |
| 53 | | Shared visual element between routes | `Hero` with stable unique tags and compatible source/destination widget trees | |
| 54 | | List/menu/card reveal with offset timings | One controller with `Interval`s, or per-item animation only when lifecycle truly differs | |
| 55 | | Spring/fling/drag or platform scroll feel | `fling`, `animateWith`, `SpringSimulation`, gesture velocity, or platform-specific `ScrollPhysics` | |
| 56 | | Motion feels wrong but code works | Tune duration, curve, interval, easing, or reduced-motion behavior before adding complexity | |
| 57 | |
| 58 | ## Resource Routing |
| 59 | |
| 60 | Read only the resources needed for the current task: |
| 61 | |
| 62 | | Task | Read/use | Purpose | |
| 63 | |---|---|---| |
| 64 | | 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 | |
| 65 | | 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 | |
| 66 | | 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 |