TouchRippleSpreadingEffect constructor
TouchRippleSpreadingEffect({
- required TouchRippleContext context,
- required VoidCallback callback,
- required bool isRejectable,
- required Offset baseOffset,
- required TouchRippleBehavior behavior,
Implementation
TouchRippleSpreadingEffect({
required this.context,
required this.callback,
required this.isRejectable,
required this.baseOffset,
required this.behavior,
}) {
assert(behavior.spreadDuration != null);
assert(behavior.spreadCurve != null);
_spreadAnimation = AnimationController(vsync: context.vsync, duration: behavior.spreadDuration!);
_spreadCurved = CurvedAnimation(parent: _spreadAnimation, curve: behavior.spreadCurve!);
// Calls the event callback function when the current animation
// progress can call the event callback function.
void checkEventCallBack() {
assert(behavior.lowerPercent != null, "Lower percent of touch ripple behavior was not initialized.");
assert(behavior.upperPercent != null, "Upper percent of touch ripple behavior was not initialized.");
final lowerPercent = behavior.lowerPercent ?? 0;
if (this.isRejectable) return;
if (this.isAttached && spreadPercent >= (behavior.eventCallBackableMinPercent ?? lowerPercent)) {
callback.call();
// Deregisters the listener as there is no longer a need to know
// when to invoke the event callback function.
_spreadAnimation.removeListener(checkEventCallBack);
}
}
_spreadAnimation.addListener(checkEventCallBack);
_spreadAnimation.addStatusListener((status) {
if (status == AnimationStatus.forward) {
_fadeAnimation.forward();
}
if (status == AnimationStatus.completed && isRejectable == false) {
_fadeAnimation.reverse();
}
});
assert(behavior.fadeInDuration != null);
assert(behavior.fadeInCurve != null);
_fadeAnimation = AnimationController(
vsync: context.vsync,
duration: behavior.fadeInDuration!,
reverseDuration: behavior.fadeOutDuration!
);
_fadeCurved = CurvedAnimation(
parent: _fadeAnimation,
curve: behavior.fadeInCurve!,
reverseCurve: behavior.fadeOutCurve!
);
_fadeAnimation.addStatusListener((status) {
if (status == AnimationStatus.dismissed) dispose();
});
isInitialized = true;
}