Skip to main content

vsync-provider-animation

Use when supplying TickerProvider to AnimationController instances in Flutter widget subtrees without writing boilerplate StatefulWidget and SingleTickerProviderStateMixin classes using vsync_provider.

설치로 이동

소스 정보

저장소
mono0926/vsync_provider
최근 소스 활동
2026년 9월 9일 03:09
감지된 SKILL.md 언어
영어
스타
23
포크
1

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
vsync_provider-animation
description
Use when supplying TickerProvider to AnimationController instances in Flutter widget subtrees without writing boilerplate StatefulWidget and SingleTickerProviderStateMixin classes using vsync_provider.
# vsync_provider Animation Ticker Guide `vsync_provider` provides a `TickerProvider` to descendant Flutter widgets using `package:provider`. This allows developers to initialize `AnimationController`s cleanly without creating boilerplate `StatefulWidget`s mixed with `SingleTickerProviderStateMixin`. ## Guidelines - **Mounting the Provider**: - Wrap the animated section with `VsyncProvider(child: ...)`. - By default, `isSingleTicker: true` is used (wrapping `SingleTickerProviderStateMixin`). If multiple concurrent animations require separate tickers within the same subtree, set `isSingleTicker: false`. - **Retrieving the Ticker**: - Inside descendant builder callbacks or child widgets, retrieve the ticker using `VsyncProvider.of(context)` (or `context.read<TickerProvider>()`). - **Instantiating Animation Controllers**: - Pass the retrieved `TickerProvider` to `AnimationController(vsync: ticker, duration: ...)`. - Ensure the created `AnimationController` is disposed when its lifecycle ends (for example, combining it with `DisposableProvider` or `ProxyProvider`). ## Examples ### 1. Providing Ticker to AnimationController via MultiProvider ```dart import 'package:disposable_provider/disposable_provider.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:vsync_provider/vsync_provider.dart'; class FadeAnimationController implements Disposable { FadeAnimationController({required TickerProvider vsync}) : animationController = AnimationController( vsync: vsync, duration: const Duration(milliseconds: 500), ); final AnimationController animationController; void play() => animationController.forward(); @override void dispose() { animationController.dispose(); } } class AnimatedScreen extends StatelessWidget { const AnimatedScreen({super.key}); @override Widget build(BuildContext context) { return MultiProvider( providers: [ const VsyncProvider(), DisposableProvider<FadeAnimationController>( create: (context) => FadeAnimationController( vsync: VsyncProvider.of(context), )..play(), ), ], child: const _AnimatedBody(), ); } } class _AnimatedBody extends StatelessWidget { const _AnimatedBody(); @override Widget build(BuildContext context) { final controller = context.watch<FadeAnimationController>(); return Scaffold( appBar: AppBar(title: const Text('Ticker Animation')), body: Center( child: FadeTransition( opacity: controller.animationController, child: const FlutterLogo(size: 100), ), ), ); } } ``` ## Common Pitfalls & Anti-Patterns - ❌ **Anti-pattern**: Attempting to initialize multiple `AnimationController`s using `isSingleTicker: true` (which triggers Flutter's runtime single-ticker assertion). - ✔️ **Correct**: Set `VsyncProvider(isSingleTicker: false)` when managing multiple tickers within the same subtree. - ❌ **Anti-pattern**: Creating `AnimationController` without disposing it. - ✔️ **Correct**: Always pair `AnimationController` with a disposal mechanism (e.g. `DisposableProvider` or an enclosing `StatefulWidget`).
GitHub에서 보기