BouncyBall constructor

BouncyBall(
  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. required Paint rubber,
  12. Curve bounce = _BOUNCY_BALL,
  13. 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

BouncyBall({
  required MaterialInkController controller,
  required RenderBox referenceBox,
  required Offset position,
  required Color color,
  required TextDirection textDirection,
  bool containedInkWell = false,
  RectCallback? rectCallback,
  BorderRadius? borderRadius,
  ShapeBorder? customBorder,
  double? radius,
  required Paint rubber,
  Curve bounce = _BOUNCY_BALL,
  VoidCallback? onRemoved,
})  : _position = position,
      _borderRadius = borderRadius ?? BorderRadius.zero,
      _customBorder = customBorder,
      _textDirection = textDirection,
      _targetRadius = radius ??
          _getTargetRadius(
              referenceBox, containedInkWell, rectCallback, position),
      _clipCallback =
          _getClipCallback(referenceBox, containedInkWell, rectCallback),
      _rubber = rubber,
      _bounce = bounce,
      super(
          controller: controller,
          referenceBox: referenceBox,
          color: color,
          onRemoved: onRemoved) {
  /// 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, // End at the opacity of provided [color]
  ));

  /// Controls the splash radius and its center. Starts upon `confirm`.
  _radiusController = AnimationController(
      duration: _kUnconfirmedDuration, vsync: controller.vsync)
    ..addListener(controller.markNeedsPaint)
    ..forward();

  /// Initial splash diameter is 0% of the target diameter,
  /// final diameter is twice as large as the target diameter.
  _radius = _radiusController.drive(Tween<double>(
    // begin: _targetRadius * 0.05,
    begin: 0,
    end: _targetRadius * 2,
  ).chain(_radiusCurveTween));

  /// Controls the splash radius and its center.
  _fadeOutController = AnimationController(
      duration: _kFadeOutDuration, vsync: controller.vsync)
    ..addListener(controller.markNeedsPaint)
    ..addStatusListener(_handleAlphaStatusChanged);
  _fadeOut = _fadeOutController.drive(
    IntTween(
      begin: color.alpha, // Start at the opacity of provided [color]
      end: 0,
    ).chain(_fadeOutIntervalTween),
  );

  controller.addInkFeature(this); // 🏓
}