GIfatahTH / animator

A Flutter library that makes animation easer. It allows for separation of animation setup from the User Interface.
BSD 3-Clause "New" or "Revised" License
227 stars 28 forks source link

AnimateWidget doesn't react with child sizes changes #63

Open AlaaEldeenYsr opened 8 months ago

AlaaEldeenYsr commented 8 months ago

When the condition returns true the animation works well, But when it gives false there is no animation Note that it works for both conditions with AnimatedSwitcher but it doesn't support triggerOnInit

AutoAnimatedWidget(
  child: Builder(
    builder: (context) {
      if (form.schedulingForm.enabled) {
        return Container(
          height: 200,
          width: double.infinity,
          color: Colors.red,
          alignment: Alignment.center,
          child: const SizedBox(),
        );
      }

      return const SizedBox();
    },
  ),
),

class AutoAnimatedWidget extends StatelessWidget {
  final Widget child;

  const AutoAnimatedWidget({
    super.key,
    required this.child,
  });

  @override
  Widget build(BuildContext context) {
    return AnimateWidget(
      curve: Curves.fastOutSlowIn,
      reverseCurve: Curves.fastOutSlowIn,
      duration: const Duration(milliseconds: 750),
      reverseDuration: const Duration(milliseconds: 750),
      triggerOnRebuild: true,
      builder: (p0, animate) => FadeTransition(
        opacity: animate.curvedAnimation,
        child: SlideTransition(
          position: Tween<Offset>(
            begin: const Offset(0, -0.2),
            end: Offset.zero,
          ).animate(animate.curvedAnimation),
          child: SizeTransition(
            sizeFactor: animate.curvedAnimation,
            axisAlignment: 1,
            child: child,
          ),
        ),
      ),
    );
  }
}
    //  AnimatedSwitcher
    return AnimatedSwitcher(
      duration: const Duration(milliseconds: 650),
      reverseDuration: const Duration(milliseconds: 650),
      switchInCurve: Curves.fastOutSlowIn,
      switchOutCurve: Curves.fastOutSlowIn,
      transitionBuilder: (child, animation) => FadeTransition(
        opacity: animation,
        child: SlideTransition(
          position: Tween<Offset>(
            begin: const Offset(0, -0.2),
            end: Offset.zero,
          ).animate(animation),
          child: SizeTransition(
            sizeFactor: animation,
            axisAlignment: 1,
            child: child,
          ),
        ),
      ),
      child: child,
    )