Skip to main content

nib_motion 0.3.5 copy "nib_motion: ^0.3.5" to clipboard
nib_motion: ^0.3.5 copied to clipboard

A declarative, physics-based Flutter animation framework inspired by Framer Motion — springs, gestures, variants, presence, FLIP layout, and GPU shaders.

Nib logo with a fountain nib forming the I

NibMotion

Declarative animation for Flutter with springs, gestures, layout transitions, and shaders.

pub.dev version pub points license platform: flutter

Website · Examples · Playground · Documentation · pub.dev


Preview #

NibMotion preview

App demo #

Daily Focus app demo


How it works #

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.

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 #

Requires Flutter 3.29 or newer. The package depends only on the Flutter SDK.

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 under tested affine parents, 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
Water (experimental) NibWaterController and NibWaterSurface for bounded decorative droplets and waves over a captured Flutter subtree
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

Layout and gesture coordinates are local logical pixels. The current geometry regressions cover scaled reorder, rotated/nonuniform presence bounds and drag, and hit exclusion during pop exits. Perspective, near-singular transforms, reorder under rotation, and pop exits that must preserve an ancestor clip across coordinate spaces are outside the verified contract. See the layout geometry contract for the tested cases and lifecycle rules.


Usage #

Gesture animations #

NibMotion(
  whileTap: const NibAnim(scale: 0.95),
  whileHover: const NibAnim(scale: 1.05),
  child: YourWidget(),
)

Variants #

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. NibFlip also rebuilds its focus and semantics wrappers when the visible face changes.


Examples and support #

Browse motion examples, read the guides, or try the playground. The example app contains runnable demos. From its directory, run flutter pub get, then flutter run -t lib/demos.dart.

The experimental water surface samples its designated Flutter background. Existing callers keep the legacy snapshot path. Opt in with sampling: NibWaterSampling.live, device-relative NibWaterQuality, clear/depth NibWaterMaterial optics and a bounded NibBubbleEmitter. The live path retains real underwater widgets and composites their sampled pixels once. Failed sampling shows direct content; this fallback is not refraction. Platform views and pixels outside the subtree are unsupported. The model is decorative 2D/2.5D, with original hit-test geometry. Browser parity and sustained performance across physical devices remain unverified.

For bugs and feature requests, open an issue with a small reproduction, your Flutter version, platform, and renderer.

License #

MIT — see LICENSE.

4
likes
0
points
1.54k
downloads

Documentation

Documentation

Publisher

verified publishernibmotion.xyz

Weekly Downloads

A declarative, physics-based Flutter animation framework inspired by Framer Motion — springs, gestures, variants, presence, FLIP layout, and GPU shaders.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on nib_motion