title: Flutter- Animation playing once for each rebuild
body: <p>I'm trying to code a custom component for a  feature in my current project. Which is increasing the height of the container by dragging and when the tap on-screen is released it should go back to how it was. The issue is whenever I restart,  the animation plays once,  for a second time if I drag the component to increase its size it works but does not go back, so the animation is not playing. The codes are following ;</p>
  <pre><code>class _HomeViewState extends State&lt;HomeView&gt; with TickerProviderStateMixin {
    HomeViewController homeController = HomeViewController();
  
    late Animation&lt;double&gt; translateBetween;
    late AnimationController customAnimationController;
  
    @override
    void initState() {
      customAnimationController = AnimationController(
          vsync: this, duration: const Duration(milliseconds: 2000));
      super.initState();
    }
  
    @override
    void dispose() {
      super.dispose();
      customAnimationController.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        backgroundColor: Colors.black,
        body: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            Obx(() {
              return Container(
                alignment: Alignment.topCenter,
                child: Column(
                  children: [
                    GestureDetector(
                      onVerticalDragUpdate: (dragUpdateDetails) {
                        var tween = Tween(
                            begin: homeController.animatedHeight, end: 20.0);
                        translateBetween = tween.animate(CurvedAnimation(
                          parent: customAnimationController,
                          curve: Curves.bounceOut,
                        ))
                          ..addListener(() {
                            homeController.animatedHeight =
                                translateBetween.value;
                          });
  
                        if (homeController.animatedHeight &gt;= 20) {
                          homeController.animatedHeight = homeController
                                  .animatedHeight -
                              dragUpdateDetails.primaryDelta!.roundToDouble() /
                                  6.5;
                        }
                        if (homeController.animatedHeight &lt; 20) {
                          homeController.animatedHeight = 20;
                        }
                        if (homeController.animatedHeight &gt;= 95) {
                          homeController.animatedHeight = 95;
                        }
                      },
                      onVerticalDragEnd: (dragEndDetails) {
                        customAnimationController.forward();
                      },
                      child: Column(
                        children: [
                          const Icon(Icons.arrow_upward_rounded),
                          SizedBox(
                            width: 20.w,
                            child: Divider(
                              color: Colors.black,
                              thickness: 0.3.w,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                width: 100.w,
                height: homeController.animatedHeight.h,
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(5.w),
                        topRight: Radius.circular(5.w))),
              );
            })
          ],
        ),
      );
    }
  }
  
  </code></pre>
  <p>I used <code>getx</code> controller for dynamically changing the size of the container.</p>
  <pre><code>class HomeViewController extends GetxController {
    final RxDouble _animatedHeight = 20.0.obs;
    double get animatedHeight =&gt; _animatedHeight.value;
    set animatedHeight(double value) =&gt; _animatedHeight.value = value;
  }
  </code></pre>
  <p><strong>GIF of issue</strong></p>
  <p><a href="https://i.stack.imgur.com/2Gb0j.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2Gb0j.gif" alt="GIF of issue " /></a></p>