How active animation effect whenever I click - flutter

Viewed 38

this is my animation code.

late AnimationController _controller;
late Animation<Color?> _color;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: Duration(milliseconds: 1350),
      vsync: this,
    )..forward();

    _color = ColorTween(begin: Colors.grey.shade400, end: Colors.amber)
        .animate(_controller);
  }

and I make Grid and apply animationBuilder.

GridView.builder(
...
child: cardButtons(subject[index], _color),)



return GestureDetector(
      onTap: () {
        doMultiSelection(item.toString());

        setState(() {});
      },
      child: AnimatedBuilder(
          animation: _color,
          builder: (context, child) {
            return Card(
              // check if the index is equal to the selected Card integer
              color: selectedItem.contains(item.toString())
                  ? _color.value
                  : Colors.grey.shade400,
              child: Container(
                height: 200,
                width: 200,
                child: Center(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
              

I want to active animation(_color.value) whenever i click. But it can olny work one time. How can I fix it?

0 Answers
Related