InkRipple constructor

InkRipple({
  1. required MaterialInkController controller,
  2. required RenderBox referenceBox,
  3. required Offset position,
  4. required Color color,
  5. required TextDirection textDirection,
  6. bool containedInkWell = false,
  7. RectCallback? rectCallback,
  8. BorderRadius? borderRadius,
  9. ShapeBorder? customBorder,
  10. double? radius,
  11. VoidCallback? onRemoved,
})

Begin a ripple, centered at position relative to referenceBox.

The controller argument is typically obtained via Material.of(context).

If containedInkWell is true, then the ripple will be sized to fit the well rectangle, then clipped to it when drawn. The well rectangle is the box returned by rectCallback, if provided, or otherwise is the bounds of the referenceBox.

If containedInkWell is false, then rectCallback should be null. The ink ripple is clipped only to the edges of the Material. This is the default.

When the ripple is removed, onRemoved will be called.

Implementation

InkRipple({
  required MaterialInkController controller,
  required super.referenceBox,
  required Offset position,
  required Color color,
  required TextDirection textDirection,
  bool containedInkWell = false,
  RectCallback? rectCallback,
  BorderRadius? borderRadius,
  super.customBorder,
  double? radius,
  super.onRemoved,
}) : _position = position,
     _borderRadius = borderRadius ?? BorderRadius.zero,
     _textDirection = textDirection,
     _targetRadius = radius ?? _getTargetRadius(referenceBox, containedInkWell, rectCallback, position),
     _clipCallback = _getClipCallback(referenceBox, containedInkWell, rectCallback),
     super(controller: controller, color: color) {

  // Immediately begin fading-in the initial splash.
  _fadeInController = AnimationController(duration: _kFadeInDuration, vsync: controller.vsync)
    ..addListener(controller.markNeedsPaint)
    ..forward();
  _fadeIn = _fadeInController.drive(IntTween(
    begin: 0,
    end: color.alpha,
  ));

  // Controls the splash radius and its center. Starts upon confirm.
  _radiusController = AnimationController(duration: _kUnconfirmedRippleDuration, vsync: controller.vsync)
    ..addListener(controller.markNeedsPaint)
    ..forward();
   // Initial splash diameter is 60% of the target diameter, final
   // diameter is 10dps larger than the target diameter.
  _radius = _radiusController.drive(
    Tween<double>(
      begin: _targetRadius * 0.30,
      end: _targetRadius + 5.0,
    ).chain(_easeCurveTween),
  );

  // Controls the splash radius and its center. Starts upon confirm however its
  // Interval delays changes until the radius expansion has completed.
  _fadeOutController = AnimationController(duration: _kFadeOutDuration, vsync: controller.vsync)
    ..addListener(controller.markNeedsPaint)
    ..addStatusListener(_handleAlphaStatusChanged);
  _fadeOut = _fadeOutController.drive(
    IntTween(
      begin: color.alpha,
      end: 0,
    ).chain(_fadeOutIntervalTween),
  );

  controller.addInkFeature(this);
}