AValue<T>.double constructor

const AValue<T>.double({
  1. required T value,
  2. Physics? physics,
  3. Duration? duration,
  4. Duration? reverseDuration,
  5. ValueChanged<T>? onValueChanged,
  6. VoidCallback? onEnd,
  7. required ValueWidgetBuilder<T> builder,
  8. Widget? child,
  9. Key? key,
})

Creates a widget that animates double values. When using a standard Curve, you must provide a duration. When using a PhysicsSimulation, the duration can be left null so the simulation itself determines the duration.

{@tool snippet} This example shows how to animate a custom value using the default constructor:

AValue<MyCustomType>(
  value: _customValue,
  normalizeOutputLength: 1,
  normalize: (value) => [value.progress],
  denormalize: (value) => MyCustomType(progress: value[0]),
  physics: Spring.snap,
  builder: (context, value, child) => CustomWidget(
    value: value,
    child: child,
  ),
)

{@end-tool}

{@tool snippet} This example shows how to animate a color with a spring physics simulation:

AValue.color(
  value: _color,
  physics: Spring.withDamping(
    mass: 1.0,
    damping: 0.7,
  ),
  builder: (context, value, child) => Container(
    color: value,
    child: child,
  ),
)

{@end-tool}

See also:

  • TweenAnimationBuilder, which provides similar functionality but only with curve-based animations
  • PhysicsSimulation, the base class for physics-based animations
  • Spring, a common physics simulation for natural-feeling animations
  • ASize, a specialized version for size animations that animates width and height at layout

Implementation

const AValue.double({
  required this.value,
  this.physics,
  this.duration,
  this.reverseDuration,
  this.onValueChanged,
  this.onEnd,
  required this.builder,
  this.child,
  super.key,
})  : normalize = AValue.normalizeDouble as List<double> Function(T),
      denormalize = AValue.denormalizeDouble as T Function(List<double>),
      normalizeOutputLength = 1;