getToggleBuilder method

AnimatedBuilder getToggleBuilder({
  1. required ValueListenable<double> animation,
  2. required Widget child,
  3. required bool toggle(),
  4. required ToggleEffectBuilder builder,
})

Returns an AnimatedBuilder that rebuilds when the boolean value returned by the toggle function changes.

Implementation

AnimatedBuilder getToggleBuilder({
  required ValueListenable<double> animation,
  required Widget child,
  required bool Function() toggle,
  required ToggleEffectBuilder builder,
}) {
  ValueNotifier<bool> notifier = ValueNotifier<bool>(toggle());
  animation.addListener(() => notifier.value = toggle());
  return AnimatedBuilder(
    animation: notifier,
    builder: (ctx, _) => builder(ctx, notifier.value, child),
  );
}