getOptimizedBuilder<U> method

AnimatedBuilder getOptimizedBuilder<U>({
  1. required ValueListenable<U> animation,
  2. Widget? child,
  3. required TransitionBuilder builder,
})

Returns an optimized AnimatedBuilder that doesn't rebuild if the value hasn't changed.

Implementation

AnimatedBuilder getOptimizedBuilder<U>({
  required ValueListenable<U> animation,
  Widget? child,
  required TransitionBuilder builder,
}) {
  U? value;
  Widget? widget;
  return AnimatedBuilder(
    animation: animation,
    builder: (ctx, _) {
      if (animation.value != value) widget = null;
      value = animation.value;
      return widget = widget ?? builder(ctx, child);
    },
  );
}