nib_motion 0.3.3
nib_motion: ^0.3.3 copied to clipboard
A declarative, physics-based Flutter animation framework inspired by Framer Motion — springs, gestures, variants, presence, FLIP layout, and GPU shaders.
NibMotion
A declarative, physics-based animation framework for Flutter — inspired by Framer Motion.
Live Demo · Documentation · pub.dev
Preview #
App Demo #
Why NibMotion? #
NibMotion lets you describe a widget's starting state, target state, and transition in one place. Use a spring when the movement should respond to interruption; use a tween when timing matters more.
Describe how your UI should look in different states — NibMotion handles the rest.
The basic NibMotion widget does not require a controller. One is available
when an interaction needs imperative control. Underneath, MotionValues carry
velocity, drivers (spring / tween / inertia / drag) that hand momentum to each
other, and render objects that repaint without rebuilding. Gestures, scroll,
layout, presence and shaders all sit on that same model — see
doc/architecture.md.
Installation #
flutter pub add nib_motion
import 'package:nib_motion/nib_motion.dart';
Quick Start #
NibMotion(
initial: const NibAnim(opacity: 0, y: 20),
animate: const NibAnim(opacity: 1, y: 0),
child: const Text('Hello NibMotion'),
)
Features #
| Category | Features |
|---|---|
| Core | Declarative API, physics-based springs, zero external dependencies |
| Gestures | whileTap, whileHover, whileDrag, whileFocus |
| Variants | State-driven UI with cascading parent → child propagation |
| Presence | Exit animations before unmount |
| Viewport | Scroll-triggered entrance animations |
| Layout | NibMotion(layout:) FLIP for position + size in any parent, shared layoutId, NibReorderable, NibLayoutGroup |
| Motion Values | Reactive values with velocity, mapRange, lazy MotionValue.computed — no widget rebuilds |
| Physics | Springs (mass/stiffness/damping or duration+bounce), NibSpring tokens, bounded inertia, independent per-axis physics (MultiSpringSolver), custom Simulations, velocity handoff between drivers |
| Keyframes | Multi-step animations with easing control |
| Text | Per-char/word/line — NibText, NibTypewriter, NibGradientText, NibTextReveal |
| Shaders | GPU effects — NibShimmer, NibDissolve |
| Liquid Glass | NibGlass with shader refraction where supported and a blur fallback; glass NibNavBar/NibScaffold |
| Navigation | NibNavBar with spring-driven pill, dot, line, highlight, or liquid water indicators |
| Presets | NibShake, NibBounce, NibPulse, NibFloat, NibFlip, NibRubberBand |
| Gestures+ | NibDraggable, NibPinch, NibSwipeDismiss |
| Timeline | NibTimeline, NibAnimationSequence for orchestration |
| Path | NibPathMotion, NibDrawPath |
| Scroll | NibParallax, NibScrollReveal |
| Debug | NibMotionDebugger, NibPerfOverlay |
| Accessibility | One reduced-motion policy (NibMotionConfig) honoured by every animated widget |
Usage #
Gesture Animations #
NibMotion(
whileTap: const NibAnim(scale: 0.95),
whileHover: const NibAnim(scale: 1.05),
child: YourWidget(),
)
Variants (State System) #
NibMotion(
variants: {
'open': NibAnim(y: 0, opacity: 1),
'closed': NibAnim(y: 20, opacity: 0),
},
initial: 'closed',
animate: isOpen ? 'open' : 'closed',
child: YourWidget(),
)
Keyframes #
NibMotion(
keyframes: [
NibKeyframe(at: 0.0, value: NibAnim(opacity: 0, y: 30)),
NibKeyframe(at: 0.6, value: NibAnim(opacity: 1, y: -5)),
NibKeyframe(at: 1.0, value: NibAnim(opacity: 1, y: 0)),
],
child: YourWidget(),
)
Exit Animations (Presence) #
NibPresence(
children: [
if (visible)
NibMotion(
key: const ValueKey('item'),
initial: const NibAnim(opacity: 0, y: 20),
animate: const NibAnim(opacity: 1, y: 0),
exit: const NibAnim(opacity: 0, y: 20),
child: YourWidget(),
),
],
)
Viewport Animations #
NibMotion(
initial: const NibAnim(opacity: 0, y: 30),
whileInView: const NibAnim(opacity: 1, y: 0),
viewport: const NibInViewConfig(amount: 0.2),
child: YourWidget(),
)
Layout Animations (FLIP) #
NibLayoutGroup(
children: tasks.map((t) => TaskCard(t)).toList(),
)
Spring Physics #
NibMotion(
animate: const NibAnim(x: 100),
transition: NibTransition.springSnappy,
child: YourWidget(),
)
Springs are interruptible: change animate mid-flight and the new motion
starts from the current position and velocity, whatever driver was running
(spring, tween, inertia, drag). See doc/interruption.md.
Reactive Motion Values #
final progress = MotionValue<double>(0);
final boost = MotionValue<double>(1);
// Single source, eager, velocity flows through the mapping:
final opacity = progress.mapRange([0, 1], [0.2, 1]);
// Several sources, lazy — evaluated when painted:
final scale = MotionValue.computed(
[progress, boost],
() => 0.9 + progress.value * 0.1 * boost.value,
);
See doc/motion-values.md.
Drag with Inertia, Bounds and Snap #
NibMotion(
drag: NibDragConfig(
constraints: Rect.fromLTRB(-200, 0, 200, 0),
releaseMode: NibDragReleaseMode.inertia, // coasts, bounces off the bounds
),
child: YourWidget(),
)
NibMotion(
drag: NibDragConfig(
snapPoints: [Offset(0, 0), Offset(0, 300)],
snapProjection: Duration(milliseconds: 150), // a flick reaches the next point
),
child: YourWidget(),
)
Liquid Glass #
NibGlass(
refractiveIndex: 1.2,
chromaticAberration: 0.03,
thickness: 20,
child: const Text('Liquid Glass'),
)
Shader refraction depends on the renderer. On unsupported renderers, the glass uses a frosted blur fallback.
Liquid navigation indicator #
NibNavBar can draw a liquid indicator that travels between items. The shader
has a gradient fallback, and reduced motion leaves the indicator at rest.
NibNavBar(
items: items,
currentIndex: selectedIndex,
onIndexChanged: (index) => setState(() => selectedIndex = index),
indicator: const NibNavIndicatorStyle(type: NibNavIndicatorType.liquid),
)
Scroll-Linked Motion #
final bridge = ScrollMotionBridge(controller: scrollController);
NibMotion(
motionValues: NibMotionValues(
opacity: bridge.scrollY.mapRange([0, 200], [1, 0]),
),
child: YourWidget(),
)
Imperative Controller #
final controller = NibMotionController();
NibMotion(
controller: controller,
child: YourWidget(),
);
await controller.start(target: const NibAnim(scale: 1.2));
Reduced Motion #
NibMotionConfig(
reducedMotion: true,
child: MyApp(),
)
Philosophy #
For continuous motion, MotionValue notifications repaint the render object
without rebuilding the widget tree on every frame. Discrete content changes,
such as a typewriter advancing to its next character, still rebuild when they
need to. Your widgets can move without asking your build method to dance on
every frame.
License #
MIT — see LICENSE.