build method
Widget
build(
- BuildContext context,
- Widget child,
- AnimationController controller,
- EffectEntry entry,
override
Builds the widgets necessary to implement the effect, based on the provided AnimationController and EffectEntry.
Implementation
@override
Widget build(
BuildContext context,
Widget child,
AnimationController controller,
EffectEntry entry,
) {
final bool shouldRotate = rotation != 0;
final bool shouldTranslate = offset != Offset.zero;
if (!shouldRotate && !shouldTranslate) return child;
final Animation<double> animation = buildAnimation(controller, entry);
final int count = (entry.duration.inMilliseconds / 1000 * hz).round();
return getOptimizedBuilder<double>(
animation: animation,
builder: (_, __) {
double value = sin(animation.value * count * pi * 2);
Widget widget = child;
if (shouldRotate) {
widget = Transform.rotate(angle: rotation * value, child: widget);
}
if (shouldTranslate) {
widget = Transform.translate(offset: offset * value, child: widget);
}
return widget;
},
);
}