FLUTTER ECOSYSTEM

lukepighetti/sprung

실제 물리 기반으로 Flutter에서 현실적인 애니메이션 제어하기

sprung 프로젝트 이미지
Stars
166
Forks
12
최근 푸시(UTC)
2022. 7. 27.
프로젝트 상태
활성
Luke Pighetti GitHub avatar
GITHUB User

Luke Pighetti ↗

Mobile engineer

ProspectBangor, ME
언어DartSwiftKotlinObjective-C

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 2 개
  • flutter{"sdk":"flutter"}
  • flutter_test개발 의존성{"sdk":"flutter"}

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

sprung

Sprung is an easy-to-consume Curve that uses real physics equations to drive your animations.

Easy to consume

Sprung has three opinionated curves, Sprung.underDamped, Sprung.criticallyDamped, and Sprung.overDamped. This is the best way to get started.

AnimatedContainer(
  curve: Sprung.underDamped,
  /// ...
),

When you want more fine control, use the default constructor which is critically damped, with overridable damping value.

AnimatedContainer(
  /// Critically damped by default with a value of `20`
  curve: Sprung(),
  /// ...
),
AnimatedContainer(
  /// Easily adjust damping value.
  curve: Sprung(19),
  /// ...
),

To build a fully custom spring simulation, use Sprung.custom. This allows you to define the spring's damping and stiffness, as well as the mass' mass and initial velocity.

AnimatedContainer(
  /// Build a custom spring
  curve: Sprung.custom(
    damping: 20,
    stiffness: 180,
    mass: 1.0,
    velocity: 0.0,
  ),
  /// ...
),

Based on Physics

Using Flutter's physics engine which leverages Newton's Second Law of Motion, Hooke's Law, and velocity based damping, we implement the following equation to create realistic spring animations.

m times x dot dot equals negative k times parenthesis x minus 1 close parenthesis minus c times x dot

Believable motion

demo of under, critically, and over damped Flutter curves

Reliable accuracy

Sprung exceeds Flutter specifications for curves by guaranteeing an error less than 1e-6. This amounts to a 0.0019px jitter at the beginning or end of a 1920px move.