attach method

dynamic attach(
  1. TouchRippleEffect effect
)

Delegates the task of adding a touch ripple effect to this controller to ensure it can be reliably detached and disposed later./

Implementation

attach(TouchRippleEffect effect) {
  if (context.overlapBehavior == TouchRippleOverlapBehavior.ignore && _states.isNotEmpty) return;
  if (context.overlapBehavior == TouchRippleOverlapBehavior.cancel) {
    _states.whereType<TouchRippleSpreadingEffect>().toList().forEach((effect) => effect.cancel());
  }

  effect.addListener(notifyListeners);
  effect.isAttached = true;
  effect.onDispose = () => detach(effect);

  assert(!_states.contains(effect), "Already exists a given ripple effect.");
  _states.add(effect);
}